ggplot2: Bring one line to the front, but save the colors
Consider the following code: library(ggplot2) foo <- data.frame(x=1:10,A=1:10,B=10:1) ggplot(melt(foo,id.vars="x"),aes(x,value,color=variable))+geom_line(size=5) I want to bring the red line (A) to the front, on top of B (see the cross point), while the colors and the order they appear in the legend do not change. Is there any way? Try this, last_plot() + aes(group=rev(variable)) Replotting the red line using a subsetted dataframe 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