Home chevron_right News chevron_right Visualizing Map Data With GGplot and Leaflet in R
arrow_backBack to News

Visualizing Map Data With GGplot and Leaflet in R

Publication
Visualizing Map Data With GGplot and Leaflet in R

A step-by-step tutorial on visualizing country-level data on a map using ggplot2 and Leaflet in R.

A new tutorial published by the DASCLAB team provides a comprehensive, step-by-step guide to visualising country-level and sub-national data on interactive and static maps using ggplot2 and Leaflet.

What the Tutorial Covers

The guide opens with data preparation using the sf package to load and clean GADM administrative boundary shapefiles for Kenya, Uganda, and Tanzania. It then walks through constructing static choropleth maps in ggplot2 using scale_fill_viridis for accessibility-compliant colour scales, annotating maps with labels and inset panels, and exporting publication-ready PDFs.

library(sf)\nlibrary(ggplot2)\nlibrary(leaflet)\n\n# Load Kenya shapefiles\nken <- st_read("kenya_counties.shp")\n\n# Choropleth with ggplot2\nggplot(ken) +\n  geom_sf(aes(fill = malaria_rate)) +\n  scale_fill_viridis_c(option = "plasma") +\n  theme_minimal() +\n  labs(title = "Malaria Prevalence by County")

The second half covers Leaflet for interactive web maps, including popups with formatted HTML, custom tile layers, and integration with Shiny for dashboard deployment.

Access

The full tutorial is available in the DASCLAB Lab Notes section and on the laboratory GitHub page. An accompanying 45-minute video walkthrough is available on the DASCLAB YouTube channel.

arrow_backAll News