与ggplot2的多面的饼图 [英] faceted piechart with ggplot2

查看:588
本文介绍了与ggplot2的多面的饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  qplot(x = factor(1),data = mtcars,fill = factor(cyl))+ 
geom_bar(width = 1)+
coord_polar(theta =y)+
facet_grid(〜gear)



但所有的饼图共享y轴比例,其中一些不包括整个圆。我尝试过使用 facet_grid(〜gear,scales =free)但它不起作用。



我如何得到所有饼图的完整圈子?

解决方案

我想你只想 position ='fill'

  ggplot (mtcars,aes(x = factor(1),fill = factor(cyl)))+ 
facet_wrap(〜gear)+
geom_bar(width = 1,position =fill)+
coord_polar(theta =y)

为了将来的参考,从 geom_bar


默认情况下,在同一个地方出现的多个x将被堆叠
通过position_stack彼此重叠。如果您希望他们从
左右避开,请参阅position_dodge。最后,position_fill通过叠加条形图,然后伸展
或挤压到相同的高度,在每个x处显示
的相对比例。



I've done a faceted piechart with ggplot2 like this:

qplot(x=factor(1), data=mtcars, fill=factor(cyl)) + 
    geom_bar(width=1) +  
    coord_polar(theta="y") + 
    facet_grid(~gear)

but as all the piecharts share the y axis scale, some of them doesn't cover the full circle. I've tried with facet_grid(~gear, scales="free") but it doesn't work.

How could I get full circles for all the piecharts?

解决方案

I think you just want position = 'fill':

ggplot(mtcars,aes(x = factor(1),fill=factor(cyl))) + 
    facet_wrap(~gear) + 
    geom_bar(width = 1,position = "fill") + 
    coord_polar(theta="y")

For future reference, from the Details section of geom_bar:

By default, multiple x's occuring in the same place will be stacked a top one another by position_stack. If you want them to be dodged from side-to-side, see position_dodge. Finally, position_fill shows relative propotions at each x by stacking the bars and then stretching or squashing to the same height.

这篇关于与ggplot2的多面的饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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