我想知道是否有更改格子中图例系列的顺序?
例如,如果我有一个重叠密度a,b和c的图,但在图例中我希望订单为c,b,a,无论如何我可以做到吗?
dat <- data.frame(dens = c(rnorm(100), rnorm(100, 10, 5), rnorm(100,-10,5))
, lines = rep(c("a", "b","c"), each = 100))
densityplot(~dens,data=dat,groups = lines,
plot.points = FALSE, ref = TRUE,
auto.key = list(corner=c(1,0.95)))
密度图图:
答案 0 :(得分:0)
你可以尝试类似下面的内容,按照相反的顺序设置lines
的级别:
library(lattice)
lev <- c('c','b','a')
dat <- data.frame(dens = c(rnorm(100), rnorm(100, 10, 5), rnorm(100,-10,5)),
lines = factor(rep(c("a", "b","c"), each = 100),
levels=lev, labels=lev, ordered = TRUE))
densityplot(~dens,data=dat,groups = lines,
plot.points = FALSE, ref = TRUE,
auto.key = list(corner=c(1,0.95)))
结果如下。