Suppose I have this plot:
library(ggplot2)
pl_data <- data.frame(x = rep(c(1, 2), times = 3), y = c(0, 1, 1, 0, .7, .7), col = rep(c("r", "b", "g"), each = 2))
ggplot(pl_data, aes(x = x, y = y, color = col)) +
geom_line(size = 3)

How to change the construction order so that the red line is displayed above the other two?
So the background is that I have stories with very similar lines and want to see certain lines in the foreground.
I assume something according to this answer, the order of stacked bars in ggplot will work. This makes the color column a factor and changes their order, but I would prefer to change it right in the ggplot call bar.
I also tried changing the order of the legends using scale_color_discrete(breaks=c("r", "g", "b"))), but this does not affect the order of construction.
Simon source
share