我用 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
的详细信息部分: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/