Pie charts in ggplot2 with variable pie sizes

I tried various ways to get facet_grid pie charts in ggplot2 to change width / radius according to another variable (force).

geom_bar takes width = 0.5 as a parameter, but is ignored after coord_polar added. Adding width=0.5 in ggplot aes or adding aes to geom_bar does not work. I do not see other suitable parameters for coord_polar . What is the easiest way to do this? The code below makes a good grid of pie charts, but does not resize the pie charts. What am I missing?

 mydata <- data.frame(side1=rep(LETTERS[1:3],3,each=9),side2=rep(LETTERS[1:3],9,each=3),widget=rep(c("X","Y","Z"),9*3),val=runif(9*3),strength=rep(c(1,2,3),3,each=3)) ggplot(mydata, aes(x="",y = val, fill = widget, width = strength)) + geom_bar(position="fill") + facet_grid(side1 ~ side2) + coord_polar("y") + opts(axis.text.x = theme_blank()) 
+7
source share
1 answer

Do you mean this?

 ggplot(mydata, aes(x=strength/2, y = val, fill = widget, width = strength)) + geom_bar(position="fill", stat="identity") + facet_grid(side1 ~ side2) + coord_polar("y") + opts(axis.text.x = theme_blank()) 

enter image description here

+18
source

All Articles