有没有人知道我可以如何控制ggplot2中的图例排序?控制ggplot2图例显示顺序
从我所看到的顺序看起来与实际比例标签相关,而不是比例尺声明顺序。更改比例标题会改变顺序。我用钻石数据集做了一个小例子来强调这一点。我正在尝试使用ggplot2进行一系列的绘图,并且我想让其中的一个变量出现在右侧。目前,虽然这只发生在其中的一些,并且我在如何执行我想要的订购时仍然感到茫然,同时保留适当的比例标签。
library(ggplot2)
diamond.data <- diamonds[sample(nrow(diamonds), 1000), ]
plot <- ggplot(diamond.data, aes(carat, price, colour = clarity, shape = cut)) +
geom_point() + opts(legend.position = "top", legend.box = "horizontal")
plot # the legend will appear shape then colour
plot + labs(colour = "A", shape = "B") # legend will be colour then shape
plot + labs(colour = "Clarity", shape = "Cut") # legend will be shape then colour
相关(尽管这个问题有一个更好的解决方案):http://stackoverflow.com/questions/10035551 /多重传奇 - 指南 - 什么是自动逻辑 - 如何改变 – 2012-07-09 16:12:53