【发布时间】:2012-07-09 23:14:00
【问题描述】:
有谁知道如何控制 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
【问题讨论】:
-
相关(虽然这个问题有更好的解决方案):stackoverflow.com/questions/10035551/…