3D population density maps built with R and Rayshader, using Kontur population data.
Population/
├── run_country.R # Entry point — run maps from here
├── scripts/
│ ├── countries.R # All country configs (edit here to tweak maps)
│ ├── helpers.R # Palette creation utilities
│ ├── create_pop_matrix.R
│ ├── plot_population_3d.R
│ ├── annotate_population_map.R
│ ├── setup_packages.R # Run once to install dependencies
│ └── legacy/ # Old per-country scripts (reference only)
├── data/ # Kontur .gpkg population + boundary files
└── output/
├── plots/ # Raw 3D renders
└── annotated/ # Final annotated maps
1. Install R Download from cran.r-project.org (v4.4+)
2. Install XQuartz (macOS only — required for rgl) Download from xquartz.org, install, then restart Mac.
3. Install R packages
Open scripts/setup_packages.R and run it once.
Open run_country.R, uncomment the country you want, and source the file:
run_country("bangladesh")
# run_country("finland")
# run_country("india")
# ... etcOutput saves automatically to output/annotated/<Country>_population_density.png.
-
Get data from Kontur:
- Population file:
kontur_population_XX_*.gpkg - Boundaries file:
kontur_boundaries_XX_*.gpkg - Place both in
data/
- Population file:
-
Add a config block to
scripts/countries.R:
my_country = list(
name = "My Country",
hex_file = "data/kontur_population_XX_20231101.gpkg",
admin_file = "data/kontur_boundaries_XX_20230628.gpkg",
crs = 3857, # find at epsg.io
size = 3000,
palette = list(source = "metbrewer", name = "Benedictus", direction = -1),
zscale = 40,
camera = list(theta = 0, phi = 55, zoom = 0.75, fov = 100),
light_dir = 315,
width = 1400, height = 1800,
solid = FALSE, shadow_depth = 0
)- Uncomment in
run_country.R:
run_country("my_country")See the comment block at the top of scripts/countries.R for what each parameter does.
Fork the repo, add your country config to scripts/countries.R, and submit a pull request.













