World map

Category: geographical

thumbnail for this post
library(tidyverse)
library(cowplot)
library(sf)
library(lwgeom)
library(rworldmap)

world_sf <- st_as_sf(getMap(resolution = "low"))

crs_wintri <- "+proj=wintri +datum=WGS84 +no_defs +over"
world_wintri <- st_transform_proj(world_sf, crs = crs_wintri)

# we will highlight the countries from which people attended our event
countries_to_highlight <- c(
  'Austria', 'Bosnia and Herzegovina', 'China', 'Colombia', 'Croatia',
  'Czech Republic', 'Denmark', 'France', 'Germany', 'Greece', 'India',
  'Indonesia', 'Iran', 'Ireland', 'Israel', 'Italy', 'Mexico', 'Netherlands',
  'Nigeria', 'Poland', 'Romania', 'Russia', 'Serbia', 'Spain', 'Sweden',
  'Switzerland', 'UK'
)

plot_data <- world_wintri %>%
  mutate(highlight = NAME %in% countries_to_highlight)

grat_wintri <-
  st_graticule(lat = c(-89.9, seq(-80, 80, 20), 89.9)) %>%
  st_transform_proj(crs = crs_wintri)

p <- ggplot() +
  geom_sf(data = grat_wintri, color = "gray30", size = 0.1) +
  geom_sf(
    data = subset(plot_data, highlight == FALSE),
    aes(fill = highlight),
    color = "#1e92bd", size = 0.2, show.legend = FALSE
  ) +
  geom_sf(
    data = subset(plot_data, highlight == TRUE),
    aes(fill = highlight),
    color = 'white', size = 0.3, show.legend = FALSE
  ) +
  coord_sf(datum = NULL) +
  scale_fill_manual(values = c("#9fd4e1", "#1e92bd")) +
  scale_color_manual(values = c("#1e92bd", "white")) +
  theme_map()
ggsave('world_1.png', p, height = 4, width = 6.43)