Controlling width of pie charts using coord_polar

1,184 views
Skip to first unread message

Dave S

unread,
Dec 20, 2011, 2:20:28 PM12/20/11
to ggplot2
Hi all:

Newbie ggplot2 question. I'm trying to make a facet grid of pie
charts and vary the size (radius) of the pie chart according to a
fourth variable.

Here's the code I'm currently using:

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)) +
geom_bar(position="fill") + facet_grid(side1 ~ side2) +
coord_polar("y") + opts(axis.text.x = theme_blank())

Adding width=strength to the aes doesn't do anything.

Thanks for any help,

Dave S.

Seung Won Kim

unread,
May 21, 2012, 9:49:59 AM5/21/12
to ggp...@googlegroups.com
Hi Dave,
 
Try 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())
 
Hope you get what you want.
 
SW
Reply all
Reply to author
Forward
0 new messages