I am new to R and trying to create a population pyramid plot similar to the first one here https://klein.uk/teaching/viz/datavis-pyramids/. I have a dataset with two variables sex and age groups that looks like this:
sex age_group
1 Male 20-30
2 Female 50-60
3 Male 70-80
4 Male 10-20
5 Female 80-90
... ... ...
This is the code I used
ggplot(data = pyramid_graph(x = age_group, fill = sex)) +
geom_bar(data = subset(pyramid_graph, sex == "F")) +
geom_bar(data = subset(pyramid_graph, sex == "M")) +
mapping = aes(y = - ..count.. ),
position = "identity") +
scale_y_continuous(labels = abs) +
coord_flip()
I do not get any errors from R but when I execute this code a blank image is produced.
Can anyone help? Thank you