如何在ggplot2的条形图中更改堆叠顺序? [英] How do I change the stacking order in a bar chart in ggplot2?

查看:3140
本文介绍了如何在ggplot2的条形图中更改堆叠顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在线条形图指南



$ p $ q $ c $ qplot(factor(cyl),data = mtcars,geom =bar,fill = factor(齿轮))

< img src =https://i.stack.imgur.com/T9H6N.pngalt =barplot使用< code> qplot< code> ggplot2< / code>>>< / a> >



我如何得到5分位于底部,4以上,3以上?

解决方案

qplot(factor(cyl),data = mtcars,geom =bar,fill = factor(gear),order = -gear)


From the online bar chart guide:

qplot(factor(cyl), data=mtcars, geom="bar", fill=factor(gear)) 

How do I get 5 to sit on the bottom, 4 above that, and 3 on top?

解决方案

qplot(factor(cyl), data=mtcars, geom="bar", fill=factor(gear), order = -gear)

这篇关于如何在ggplot2的条形图中更改堆叠顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆