Bubble map
As a variation of a bubble chart, bubble maps display bubbles over geographical regions rather than the cartesian plane. The size or area of the bubble indicates the value of the particular variable, with the position on the map indicating location. Bubble maps are useful for comparing proportions against geographic regions without the issues caused by the size of different areas, as you would have in choropleth maps.
More about: Bubble map - Other tutorials: D3
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
library(sf)
# Data URL
df_url <- "https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/geospatial/bubble_map.csv"
poly_url <- "https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/geospatial/world_polygons_simplified.json"
line_url <- "https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/geospatial/world_lines_simplified.json"
# Read and transform data
df <- read_csv(df_url) |>
st_as_sf(
coords = c("lon", "lat"),
crs = 4326
)
poly <- read_sf(poly_url) |>
st_set_crs(4326)
line <- read_sf(line_url) |>
mutate(
type = as_factor(type) |>
fct_relevel("solid", "dashed", "dotted", "dashed-dot")
) |>
st_set_crs(4326)
# Plot
ggplot() +
geom_sf(
data = poly,
fill = "#EAE6E4",
color = "transparent"
) +
geom_sf(
data = line,
aes(linetype = type),
color = "#A8AAAD",
linewidth = .25,
show.legend = FALSE
) +
geom_sf(
data = df,
aes(size = ref),
shape = 21,
fill = unhcr_pal(n = 1, "pal_blue"),
color = unhcr_pal(n = 5, "pal_blue")[5],
alpha = 0.3
) +
labs(
title = "Global refugee displacement by country of origin | 2021",
caption = "<em>The boundaries and names shown and the designations used on this map do not imply official endorsement or acceptance by the United Nations.</em><br>Source: UNHCR Refugee Data Finder - © UNHCR, The UN Refugee Agency"
) +
scale_linetype_manual(values = c(1, 2, 3, 4)) +
scale_size_area(
max_size = 12,
labels = scales::label_number(
scale_cut = cut_short_scale()
),
breaks = c(1e5, 1e6, 5e6)
) +
coord_sf(crs = st_crs("ESRI:54030")) +
theme_unhcr(void = TRUE)
Choropleth map
A choropleth map is a type of thematic map in which areas are shaded or patterned according to a data variable. The variable is categorized into intervals, with each interval represented by a colour, and the map filled accordingly.
More about: Choropleth map - Other tutorials: D3
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
library(sf)
# Data URL
df <- read_csv("https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/geospatial/choropleth_map.csv")
poly_url <- "https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/geospatial/world_polygons_simplified.json"
line_url <- "https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/geospatial/world_lines_simplified.json"
# Read and transform data
poly <- read_sf(poly_url) |>
st_set_crs(4326) |>
left_join(df, by = c("color_code" = "iso3")) |>
mutate(legend = case_when(
refugees < 1e4 ~ "<10k",
refugees < 1e5 ~ "10k-100k",
refugees < 1e6 ~ "100k-1M",
is.na(refugees) ~ NA_character_,
TRUE ~ ">1M"
)) |>
mutate(legend = as_factor(legend) |>
fct_relevel("<10k", "10k-100k", "100k-1M", ">1M"))
line <- read_sf(line_url) |>
mutate(
type = as_factor(type) |>
fct_relevel("solid", "dashed", "dotted", "dashed-dot")
) |>
st_set_crs(4326)
# Plot
ggplot() +
geom_sf(
data = poly,
aes(fill = legend),
color = "transparent"
) +
geom_sf(
data = line,
aes(linetype = type),
color = "white",
linewidth = .25,
show.legend = FALSE
) +
labs(
title = "Global refugee displacement by country of asylum | 2021",
caption = "<em>The boundaries and names shown and the designations used on this map do not imply official endorsement or acceptance by the United Nations.</em><br>Source: UNHCR Refugee Data Finder - © UNHCR, The UN Refugee Agency"
) +
scale_linetype_manual(values = c(1, 2, 3, 4)) +
scale_fill_unhcr_d(palette = "pal_blue") +
coord_sf(crs = st_crs("ESRI:54030")) +
theme_unhcr(void = TRUE, legend_text_size = 9)