Demographic Pyramids in R
- Bernard Kilonzo
- 11 minutes ago
- 2 min read

Overview
A demographic pyramid-also called a population pyramid-is a visual tool used to show the age and sex structure of a population. Picture two bar graphs stacked back-to-back: one side usually represents males, the other females, and each horizontal bar corresponds to a specific age group. The youngest are at the bottom, and it climbs upward with age.
A population pyramid provides key insights about a country’s demographic structure in the following ways:
Shape tells a story: A wide base suggests a high birth rate (lots of kids), while a narrow top indicates fewer elderly individuals—typical of fast-growing populations.
Balanced or skewed: If one side is noticeably wider, it might hint at gender imbalances due to migration, conflict, or cultural factors.
It predicts the future: By looking at the structure, planners can anticipate needs like schools, jobs, healthcare, or retirement services.
In this article, I will demonstrate how to create a population pyramid in R with ggplot2.
1. Basic Population Pyramid
This visualization showcases the population distribution of Kenya as per the latest census figures of 2019. The viz demonstrates how you can create a basic population pyramid in R.

Replicate the visualizations: Link to Code
2. Population Pyramid (Comparing Two Periods)
This visualization demonstrates how you can compare population distribution for two periods in a single view. The visualization uses the census data to compare population distribution between the year 2009 and 2019.

3. Population Pyramid (Comparing Three Periods)
What about when you need to compare population distribution in three or more periods? This visualization demonstrates how you can compare population distribution in three timelines – particularly in this case I am comparing population distribution between 1999, 2009, and 2019.

Build similar viz in Tableau: Explore how to create a population pyramid chart in Tableau.
Conclusion
The population pyramid serves as a powerful graphical representation of a country's demographic structure. By visualizing the distribution of age groups across gender, it highlights key trends such as population growth, youth bulges, aging populations, and potential demographic dividends or burdens. Population pyramids are essential for understanding the past and present demographic landscape, and for forecasting future challenges and opportunities.
If you like the work we do and would like to work with us, drop us an email on our contacts page and we’ll reach out!
Thank you for reading!