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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With