Skip to content

Instantly share code, notes, and snippets.

@AWinterman
Created July 3, 2012 16:05
Show Gist options
  • Save AWinterman/3040685 to your computer and use it in GitHub Desktop.
Save AWinterman/3040685 to your computer and use it in GitHub Desktop.
bar chart in polar coordinates
G = ggplot(data = frame
, aes(x = 10
, label = New.HIV.Infections.due.to.MTCT
, y = sqrt(New.HIV.Infections.due.to.MTCT)
, fill = contribution.to.global.MTCT.burden))+
geom_bar( stat= "identity", position = "identity")
#This will make a stacked bar chart with one column, with colors determined by the contribution to the global burden.
#I'm going to map x to angle and y to radius (hence the square root above)
G = G+theme_bw()+opts(axis.text.x = theme_blank(), legend.position = "bottom", axis.ticks = theme_blank() )+coord_polar(theta = "x")
#This converts the bar to polar coordinates
G = G+scale_fill_continuous(name = add_break("contribution.to.global.MTCT.burden", "."), guide = guide_colorbar(barwidth = 10))+
scale_y_continuous(add_break("SQRT New.HIV.Infections.due.to.MTCT", "."))+scale_x_continuous(name = "")
#This handles x and y labels, color guide, etc.
G+ facet_wrap(~ country, ncol = 8) #make one graph per country.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment