A comprehensive R-based project that analyzes the Gapminder dataset (1952–2007) to explore global trends in life expectancy, GDP per capita, and population. The analysis produces a suite of 12 visualizations, fits a regression model, and renders an HTML report.
- Project Overview
- Features & Charts
- Prerequisites
- Installation
- Usage
- File Structure
- Scripts & Automation
- Docker & Containerization
- Extending & Customizing
- Data Source & Citations
- License
This repository contains everything needed to:
- Fetch and prepare the Gapminder dataset via the
gapminderR package. - Compute key metrics (global averages, per-country snapshots).
- Visualize 12 charts illustrating temporal trends, economic relationships, continental comparisons, and population impacts.
- Model the relationship between life expectancy and GDP per capita.
- Automate the workflow via shell scripts, a Makefile, and Docker.
- Render a polished RMarkdown report (
Gapminder_report.html).
Ideal for students, educators, data scientists, and anyone interested in global development metrics.
- Global Average Life Expectancy Over Time
- Global Average GDP per Capita Over Time
- Global Total Population Over Time
- Scatter: Life Expectancy vs. GDP per Capita (2007)
- Regression: Life Expectancy ~ log(GDP per Capita)
- Top 10 Countries by Life Expectancy (2007)
- Boxplot: Life Expectancy by Continent (2007)
- Violin: GDP per Capita by Continent (2007)
- Line: Average Life Expectancy by Continent Over Time
- Density: Life Expectancy Distribution by Continent (2007)
- Heatmap: Average Life Expectancy by Year & Continent
- Bubble Plot: GDP vs. Life Expectancy Sized by Population (2007)
Each plot is saved to gap-<index>.png and displayed in the R session.
- R ≥ 4.0
- RStudio (optional, but recommended)
- Internet connection (to install R packages and fetch data)
ggplot2dplyrgapminderscalesviridistidyrforcatszoormarkdown(for report rendering)
The main script auto-installs any missing packages.
-
Clone this repository:
git clone https://github.com/yourusername/gapminder-analysis.git cd gapminder-analysis -
Install R (if not already).
-
(Optional) Copy
.env.exampleto.envto customize environment variables.
bash scripts/run_gapminder.shAll 12 charts will print and save as gap-1.png … gap-12.png.
bash scripts/render_report.shThis produces Gapminder_report.html.
make reportEquivalent to running analysis and report steps.
.
├── Gapminder_Analysis.R # Main R script
├── Gapminder_Analysis.Rmd # RMarkdown report
├── Gapminder_report.html # Generated HTML report
├── gap-*.png # Saved plot images
├── scripts/
│ ├── run_gapminder.sh # Runs the analysis script
│ └── render_report.sh # Renders the RMarkdown
├── Makefile # Make targets for automation
├── Dockerfile # Container definition
├── docker-compose.yml # Compose for containerized run
├── .env.example # Sample environment config
└── README.md # This file
-
scripts/run_gapminder.shRunsGapminder_Analysis.Rto produce and save all plots. -
scripts/render_report.shRendersGapminder_Analysis.RmdtoGapminder_report.html. -
Makefilemake analysis— run shell script to generate plotsmake report— run analysis + render reportmake clean— delete images & report
Build and run in a container:
docker-compose up --buildThis will:
- Install system and R dependencies
- Run the analysis script
- Render the RMarkdown report
All files are shared via a bind mount.
- Add more plots: insert new code chunks in
Gapminder_Analysis.Ror.Rmd. - Parameterize: use YAML or command-line args to filter years or continents.
- CI/CD: integrate with GitHub Actions to auto-build the report on push.
- Data sources: replace Gapminder with another tidy dataset for similar workflows.
-
Gapminder dataset via R package:
install.packages("gapminder") -
R Packages: see CRAN for
ggplot2,dplyr, etc.
This project is licensed under the MIT License. See LICENSE for details.











