如何使用ggplot / geom_bar来订购休息时间 [英] How to order breaks with ggplot / geom_bar
问题描述
变量重要性顺序
1 foo 0.06977263 1
2 bar 0.05532474 2
3 baz 0.03589902 3
4 alpha 0.03552195 4
5 beta 0.03489081 5
...
使用breaks =变量绘制上述图时,我希望保留订单,而不是按字母顺序排列。
我正在渲染:
ggplot(data,aes(x = variable,weight = importance,fill = variable))+
geom_bar()+
coord_flip()+ opts(legend.position ='none')
然而,变量名称是按字母顺序排列的,而不是数据框内的顺序。我曾看过一篇关于在aes中使用订单的帖子,但似乎没有任何效果。
我正在寻找一个符合订单列。
似乎有类似的问题,但坦率地说,在这种情况下并不理解答案。
b $ b试试:
data $ variable< ; - factor(数据$变量,levels = levels(数据$变量)[order(-data $ order)])
发件人: ggplot2排序情节第二部分
I have a data.frame with entries like:
variable importance order 1 foo 0.06977263 1 2 bar 0.05532474 2 3 baz 0.03589902 3 4 alpha 0.03552195 4 5 beta 0.03489081 5 ...
When plotting the above, with the breaks = variable, I would like for the order to be preserved, rather than placed in alphabetical order.
I am rendering with:
ggplot (data, aes(x=variable, weight=importance, fill=variable)) + geom_bar() + coord_flip() + opts(legend.position='none')
However, the ordering of the variable names is alphabetical, and not the order within the data frame. I had seen a post about using "order" in aes, but appears to have no effect.
I am looking to have a breaks ordering in-line with the "order" column.
There seems to be a similar question How to change the order of discrete x scale in ggplot, but frankly, did not understand the answer in this context.
Try:
data$variable <- factor(data$variable, levels=levels(data$variable)[order(-data$order)])
From: ggplot2 sorting a plot Part II
这篇关于如何使用ggplot / geom_bar来订购休息时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!