R 当条形图表示发生次数时,如何对条形图进行排序?

R 当条形图表示发生次数时,如何对条形图进行排序?,r,ggplot2,bar-chart,R,Ggplot2,Bar Chart,我用R画了一个条形图: ggplot(data, aes(x=rating, fill=rating)) + geom_bar(stat="count") + ggtitle("Rating in stories")+ coord_flip()+ xlab("rating")+ ylab("number of stories")+ theme(legend.position="none") 结果

我用R画了一个条形图:

ggplot(data, aes(x=rating, fill=rating)) +
geom_bar(stat="count") +
ggtitle("Rating in stories")+
coord_flip()+
xlab("rating")+
ylab("number of stories")+
theme(legend.position="none")
结果是。 条形图表示特定值(M、T、K或K+)在额定变量中出现的次数。
如何按递减顺序对条进行排序?

好的,我找到了我要查找的内容。我需要在变量上使用fct_rev(fct_informeq())

ggplot(data, aes(forcats::fct_rev(fct_infreq(rating)), fill=rating)) +
geom_bar(stat = "count") +
ggtitle("Rating in stories")+
coord_flip()+
xlab("rating")+
ylab("number of stories")+
theme(legend.position="none")

很高兴你找到了你想要的答案。但是,如果您能以可复制的格式向我们提供一些数据,通常会更好。了解。提供只查看代码而不查看数据的解决方案有点困难。