I'm new to geoplotting and I want to use sf
to plot a map of Germany on the state level, with state values colored by a variable in a separate data set. How do I best go about this?
I have loaded the data and the sf object like this:
library(sf)
library(tidyverse)
theme_set(theme_bw())
library(rnaturalearth)
library(rnaturalearthdata)
dat <- read.table(text="
state value
Sachsen 10
Bayern 30
Rheinland-Pfalz 50
Saarland 70
Schleswig-Holstein 90
Niedersachsen 100
Nordrhein-Westfalen 80
Baden-Württemberg 60
Brandenburg 40
Mecklenburg-Vorpommern 20
Bremen 40
Hamburg 60
Hessen 15
Berlin 10
Thüringen 80
Sachsen-Anhalt 20
", header=T)
ger_fedstates <- ne_states(country = "germany")
sp::plot(ne_states(country = "germany"))
How do I now color each state by the value in dat$value
? I'm at a loss of how to best combine these two.