rggplot2rnaturalearth

Countries FR and NO seem to be ignored by rnaturalearth


I've created the very simple CSV country-test.csv:

Country, Value
DE,1
US,2
FR,3
NO,4

I want to create a world map with different colors for these countries and tried:

library(tidyverse)
library(rnaturalearth)
library(sf)
library(ggplot2)

# Read the CSV data
data <- read.csv("country-test.csv", header = TRUE)

# Get world map data
world <- ne_countries(scale = "medium", returnclass = "sf")

# Join data with world map
world_data <- left_join(world, data, by = c("iso_a2" = "Country"))

ggplot(world_data) +
  geom_sf(aes(fill = Value)) +
  scale_fill_gradient(low = "lightblue", high = "darkblue") +
  theme_minimal()

Unfortunately FR (France) and NO (Norway) are not put on the map. What might be wrong here?

I tried debugging somehow but had no idea what to do to get all four countries printed.


Solution

  • tl;dr The recommendation from the linked discussion is to use the iso_a2_eh field ("eh" apparently stands for '"eh" as in okay but not great', i.e. imprecise) instead of iso_a2 when matching.


    This is apparently a known issue with the underlying naturalearth data set, or more specifically with imprecise upstream definitions.

    Natural Earth's practice is to be strict on the ISO code mappings.

    ... which I take to mean (without digging into the gory details too much) that there is some issue with the "FR" and "NO" codes not matching something upstream exactly (or matching something ambiguously), so Natural Earth chooses not to include those codes. To be honest, I don't really understand the issue ...