相关疑难解决方法(0)

控制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
Run Code Online (Sandbox Code Playgroud)

r ggplot2

68
推荐指数
2
解决办法
2万
查看次数

标签 统计

ggplot2 ×1

r ×1