Population pyramids in ggplot

I have downloaded the data on resident population by age and sex from Demo ISTAT . Here is an example made using 2015 data from a North-Western Italian village of 2587 souls, Caltignaga, famous for its Roman aqueduct:

age sex   value
0   males  8
1   males  10
2   males  11
3   males  5
4   males  11
5   males  20
....

Pyramid_smooth_g.png

ggplot(data=dt) +
geom_bar(aes(age,value,group=sex,fill=sex), stat = "identity",subset(dt1,dt1$sex=="females")) +
geom_bar(aes(age,-value,group=sex,fill=sex), stat = "identity",subset(dt1,dt1$sex=="males")) +
scale_y_continuous(breaks=seq(-100,40,10),labels=abs(seq(-100,40,10))) +
coord_flip()

extra annotation for the text and arrow:
geom_curve(
aes(x = 96, y = 2, xend = 96, yend = 10),
data = dt1,curvature = -0.2,
arrow = arrow(length = unit(0.03, "npc")))+
annotate("text", x = 96, y = 16, label = "This is my grandma!",fontface="italic")

 

Advertisements

Author: acarioli

is a PostDoc at the Geography and Environment department of the University of Southampton, WorldPop project team. She is also affiliated researcher at CED, UAB and Dondena Centre. Her interests include spatial econometrics and modeling, bayesian methods, machine learning processes, forecasting, micro-data simulation, and data visualization. Demo-traveler, Mac enthusiast, R zealot and Rladies member.