Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

r - faceted piechart with ggplot2

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)

enter image description here

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...