r - 带有ggplot2的多面饼图

标签 r ggplot2 pie-chart

我用 ggplot2 做了一个多面饼图,如下所示:

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

enter image description here

但由于所有饼图都共享 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 的详细信息部分:

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.

关于r - 带有ggplot2的多面饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18537378/

相关文章:

r - geom_segment 箭头设置 - 头部与线宽度相同

python - Pyplot 饼图错误,值较小

r - 为什么包装函数不能按预期工作?

r - 在 write 函数中 append 文本 [R]

r - 如何从整体中提取数据框的一部分?

r - ggplot2 2.1.0 破坏了我的代码?次要变换轴现在显示不正确

r - facet_wrap的百分比直方图

r - 带有 geom_tile 的情节中的多个图例

javascript - 任意图表 : How to add animation in Pie or funnel chart of AnyChart7. 1

javascript - 饼图自定义图例