我的df:
summary2
Source: local data frame [4 x 2]
mean Patch
(dbl) (fctr)
1 3.210293 Scotland
2 3.555884 UK
3 3.883458 UK North
4 4.003116 Department
df已经按平均排序,但是当我绘制条形图时,它会弄乱订单。
以下是代码:
ggplot(summary2,aes(x=Patch,y=mean, fill = Patch)) +
geom_bar(colour="black",stat = "identity")
如何将它放入有序条形图中?
答案 0 :(得分:1)
完全受this post:
启发的解决方案df = read.table(header = TRUE,
text = 'mean Patch
1 3.210293 Scotland
2 3.555884 UK
3 3.883458 UKNorth
4 4.003116 Department')
ggplot(df,aes(x=Patch,y=mean, fill = Patch)) +
geom_bar(colour="black",stat = "identity") +
scale_x_discrete(limits = df$Patch[order(df$mean)])
还有通过重新排序提到的其他解决方案。