Show the code
load("social-service-agency.RData")
Andy Grogan-Kaylor
September 9, 2023
A quick look at moving from bar charts to pie charts.
A longer explanation of some issues is here: https://agrogan1.github.io/posts/bar-charts-in-ggplot2/
age | program | gender |
---|---|---|
23 | Program B | Male |
39 | Program C | Female |
26 | Program C | Female |
24 | Program D | Male |
36 | Program C | Female |
33 | Program C | Male |
ggplot
One approach …
# position = position_fill() makes the slices
# fill the pie in each facet
ggplot(clients, # data I am using
aes(x = 1, # x is back to 1
fill = gender)) + # fill is gender
geom_bar(position = position_fill()) + # use bars
coord_polar(theta = "y") + # polar coordinates
facet_wrap(~program) + # facet wrap on program
theme_void() # blank theme for pie charts