ggplot2
A nice feature of ggplot2
is the ability to apply differing coordinate systems. While most often graphics are expressed on Cartesian coordinates, sometimes it is interesting to use different bases. In this gist, I show a few applications of polar coordinates.
library(ggplot2)
## No 'x' mapping; bars of constant width; polar coordinates with theta
## applied to the Y axis
ggplot(diamonds, aes(x = "", fill = clarity)) + geom_bar(width = 1) + coord_polar(theta = "y") +
scale_fill_brewer(palette = "Accent")
## 'x' now mapped to clarity; bar width still of constant width; polar
## coordinates with theta applied to x.
ggplot(diamonds, aes(x = clarity, fill = clarity)) + geom_bar(width = 1) + coord_polar(theta = "x") +
scale_fill_brewer(palette = "Accent")
## Incorporating another variable on fill gives the 'Wind Rose' plot:
ggplot(diamonds, aes(x = clarity, fill = cut)) + geom_bar(width = 1) + coord_polar(theta = "x") +
scale_fill_brewer(palette = "Accent")
## Putting theta on 'Y' gives a weird sort of bullseye plot. Uses a width of
## .9 to produce space between bars.
ggplot(diamonds, aes(x = clarity, fill = clarity)) + geom_bar(width = 0.9) +
coord_polar(theta = "y") + scale_fill_brewer(palette = "Accent")
## This becomes more interesting with a different fill:
ggplot(diamonds, aes(x = clarity, fill = cut)) + geom_bar(width = 0.9) + coord_polar(theta = "y") +
scale_fill_brewer(palette = "Accent")