Replacing the red line using a subset of the data does the trick.
library(ggplot2) foo <- data.frame(x=1:10,A=1:10,B=10:1) require(reshape2) fooM <- melt(foo,id.vars="x") p<-ggplot() p<-p+geom_line(data=fooM[fooM$variable!="A",],aes(x,value,color=variable),size=5) p<-p+geom_line(data=fooM[fooM$variable=="A",],aes(x,value,color=variable),size=5) p
EDIT: Note that ggplot sequentially applies layers to each other - this is best used when plotting lines by lines.
EDIT2: @tonytonov is right that you can avoid duplicate repeating the same thing. Modified my answer to draw everything except A for the first time, then only A. The result remains the same, and now it is also compatible with transparency or big data;)
source share