::: {.cell hash='08_Maps_cache/revealjs/spatial-join_dbbcb0312c0c43316b48ecdcfade5268'}

```{.r .cell-code}
cities <- read_sf("data/italian-cities.shp") %>%
  # we select just the city name, discarding 
  # any other information except the geometry
  select(name = city) %>% 
  st_transform("+proj=merc")
provinces <- ne_states(country="Italy", returnclass="sf") %>%
  # we select just the province name and its geometry (implicitly)
  select(province = name) %>% 
  st_transform("+proj=merc")

# we join the two datasets based on the spatial information
joined <- st_join(cities, provinces, left=FALSE) 

ggplot(joined, aes(color=province)) +
  geom_sf(data=provinces, size=.1) +
  geom_sf(size=1) +
  theme_void() +
  theme(legend.position="none")
```
:::