【发布时间】:2017-05-04 13:35:33
【问题描述】:
假设我有这个情节:
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)
如何更改绘图顺序,使红线 绘制在其他两个上方?
因此,背景是我的情节非常相似 行,并希望在前景中看到特定的行。
我想这个答案order of stacked bars in ggplot 的内容会起作用。它使颜色列成为因素并改变它们的顺序,但我更愿意改变 这直接在 ggplot 调用的一行中。
我还尝试使用scale_color_discrete(breaks=c("r", "g", "b")) 更改图例顺序),
但这也不影响绘图顺序。
【问题讨论】: