I have many lines in one plot and to differentiate between them I want to combine color and linetype following the suggestion here:
This works fine. However, I want to add another geom with a fixed color. This color overwrites all other colors, but only when using the combination of color and linetype as described above. Here is an example:
library(ggplot2)
library(RColorBrewer)
d <- data.frame(x=c(rep(1,10), rep(2,10)),
y=c(seq(1,10), seq(2,11)),
model=letters[seq(1, 10)])
p1 <- ggplot(d, aes(x=x, y=y, color=model)) + geom_line()
p2 <- ggplot(d, aes(x=x, y=y, color=model, linetype=model)) + geom_line() +
scale_linetype_manual(values = c(rep("solid", 5), rep("dashed", 5))) +
scale_color_manual(values = c(brewer.pal(5, "Paired"), brewer.pal(5, "Paired")))
## similar colors
p1
## works as expected but similar colors
p1 + stat_summary(fun.y=mean, colour="black", geom="line")
## easier to distinguish
p2
## all elements black
p2 + stat_summary(fun.y=mean, colour="black", geom="line")