0

I am having difficulty trying to change the dependent color from the legend go to geom_line instead of geom_area. I have this plot which I am pretty happy with but the only thing I would add is replacing the dependancy where the legend takes the color from.

#custom color vector
col <- c("#004d8d", "#cc2701", "#e5b400")

#plot
p2 <- ggplot(data = densdf1, mapping = aes(x = x, y = y)) +
  geom_area(data = densdf1[densdf1$CI,], 
            aes(color = Electrode),
            outline.type = "full", alpha = 0.3, size = 1) +
  geom_line(aes(color = Electrode), size = 1) +
  scale_color_manual(values = col, breaks = c("Fz", "Cz", "Pz")) +
  scale_fill_manual(values = col, breaks = c("Fz", "Cz", "Pz")) +
  guides(colour = "none") +
  geom_vline(xintercept = 0) +
  lims(x = c(-3, 2), y = c(0, 2.25)) +
  labs(title="INTERVAL 275-350ms", x="VALUES", y="DENSITY") +
  theme_bw() +   
  theme(axis.text=element_text(size=10),
        axis.title=element_text(size=12),
        plot.title=element_text(size=14))

As you can see in the picture, the code gives me this plot, and the legend takes its default color from the geom_area, wich is translucent (on purpose), instead of the geom_line color, which is the full color.

Plot with legend

Is there a way to force the legend to take the color from the line fill?

Thanks in advance!

Unai Vicente
  • 367
  • 3
  • 10

0 Answers0