top of page

Unlocking Spatial Insights: Creating Point Maps with R

hands typing on a laptop

Overview

A point map displays spatial data by plotting discrete occurrences or features directly onto a geographic base. Each point signifies the presence or occurrence of a particular event, object, or attribute at a precise location. These maps are used to show where things happen, rather than how much or how often - though additional data (like size or color of the point) can be layered to convey more information.

Example of a Point Map

a point map showing fatalities due to conflicts in Africa
Replicate the visualization: Link to code

Step-by-Step Guide

Loading the required libraries

load libraries
library(tidyverse)
library(maps)

Loading data (in this case political conflict data in Africa)

load data
conflict_data<-read.csv("https://raw.githubusercontent.com/bernardkilonzo-rigor/geoinsights/refs/heads/main/data/Conflict%20Fatalities.csv")

Grouping the fatalities into bins to be used when applying color to the point map.

grouping fatalities cases into bins
conflict_data<-conflict_data%>%mutate(bin = case_when(
  Fatalities<=0 ~"0",
  Fatalities<=10 ~"1-10",
  Fatalities<=20 ~"11-20",
  Fatalities<=30 ~"21-30",
  Fatalities<=50 ~"31-50",
  Fatalities<=100 ~"51-100",
  Fatalities>100 ~"101+"
))

Ordering the bins using a factor.

ordering the bins
conflict_data$bin<-factor(conflict_data$bin,
                          levels = c("0","1-10","11-20","21-30",
                                     "31-50","51-100","101+"))

Loading the world map data

load world map data
world_map<-map_data("world")

Extracting the Africa map data from world map data through filtering – this will be used as a base map in our plot.

extracting the base map of Africa (by filtering regions)
africa_map <- world_map %>%filter(region %in% c("Algeria","Angola","Benin","Botswana","Burkina Faso","Burundi","Cabo Verde","Cameroon","Central African Republic","Chad","Comoros","Republic of Congo","Democratic Republic of the Congo","Djibouti","Egypt","Equatorial Guinea","Eritrea","Eswatini","Ethiopia","Gabon","Gambia","Ghana","Guinea","Guinea-Bissau","Ivory Coast","Kenya","Lesotho","Liberia","Libya","Madagascar","Malawi","Mali","Mauritania","Mauritius","Morocco","Mozambique","Namibia","Niger","Nigeria","Rwanda","Sao Tome and Principe","Senegal","Seychelles","Sierra Leone","Somalia","South Africa","South Sudan","Sudan","Tanzania","Togo","Tunisia","Uganda","Western Sahara","Zambia","Zimbabwe"))

Creating a simple point map in R

creating point distribution map
ggplot()+
  geom_polygon(data = africa_map, aes(x =long, y = lat, group = group),
               fill ="white", color = "gray35", linewidth =0.1)+
  geom_point(data = conflict_data, aes(x = Longitude, y = Latitude, size = Fatalities, color = bin), alpha = 0.4)+
  scale_color_manual(values = c("#2c5c8a","#5f81af","#77acd3","#d9d5c9",
                                "#f69035","#d45b21","#9e3d22"))+
  coord_quickmap()

Executing the above code generates the view below.

a basic point map created in R with ggplot2

Formatting the point map using the additional line of code.

creating point distribution map + formatting
ggplot()+
  geom_polygon(data = africa_map, aes(x =long, y = lat, group = group),
               fill ="white", color = "gray35", linewidth =0.1)+
  geom_point(data = conflict_data, aes(x = Longitude, y = Latitude, size = Fatalities, color = bin), alpha = 0.4)+
  scale_color_manual(values = c("#2c5c8a","#5f81af","#77acd3","#d9d5c9",
                                "#f69035","#d45b21","#9e3d22"))+
  coord_quickmap()+
labs(title = "Political Conflict in Africa (1997 - 2017)",
       subtitle = "Reported Fatalities by Location",
       caption = "Viz by: Bernard Kilonzo", color = "Fatalities")+
  theme(panel.background = element_blank(),
        panel.grid = element_blank(),
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        plot.background = element_rect(fill = "gray95",color = "gray95"),
        legend.background = element_rect(fill = "gray95"),
        legend.title = element_text(family = "serif", size = 10, color = "gray25"),
        legend.text = element_text(family = "serif", size = 9, color = "gray25"),
        plot.title = element_text(family = "serif", face = "bold", size = 12, color = "gray20"),
        plot.subtitle = element_text(family = "serif", size = 10, color = "gray20"),
        plot.caption = element_text(family = "serif", face = "italic", size = 9, color = "gray35"))

Executing the above code generates the view below.

a final point map showcasing number of fatalities due to conflicts in Africa

Conclusion

Creating point maps in R is a straightforward yet powerful way to visualize spatial data and uncover geographic patterns. With packages like ggplot2, sf, and leaflet, users can plot coordinates as individual points on a map, enriching them with color, shape, or size to reflect additional variables. These maps help identify trends, clusters, and anomalies across regions. Whether you're visualizing store locations, wildlife sightings, or public service access, R gives you the tools to bring location-based insights to life with clarity and flexibility.

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!

Tags:

 
 
Original.png

We Support You Deliver Business-Focused Solutions That Enable Data-Driven Decision Making.

  • Tableau profile
  • YouTube
  • White LinkedIn Icon
  • Facebook
  • X

QUICK LINKS

CONTACT US

WhatsApp: +254 738 307 495

East Gate Mall, Donholm

3rd Floor Suite No. 3i

Nairobi, Kenya

Join our mailing list

bottom of page