I am working on a ggplot + geom_sf map in which I display cities and additionally, I want to illustrate that the cities belong to specific regions. In short, I want to draw circles (comparable to geom_encircle()) that put together the cities to a region (e.g. "West"). enter image description here enter image description here
Unfortunately, I do not end up in the desired result with geom_encircle(). Do you have ideas/hints on how I could proceed?
The underlying map data is a sf object (geometry type: Multipolygon, dimension XY), the cities data is a sf object (geometry type: point, dimension XY) including a column called 'region' that shall define, which cities shall be encircled as a group.
The map data (Germany) is extracted from
https://opendata.arcgis.com/datasets/2842f834961b4702a179bdcb08f7b6c9_0.zip?outSR=%7B%22latestWkid%22%3A3857%2C%22wkid%22%3A102100%7D
where the shapefile "Bundesländer 2018 mit Einwohnerzahl" from ESRI Deutschland can be downloaded.
The transformation was made with the code:
Deutschland <- st_read("xn--Bundeslnder_2018_mit_Einwohnerzahl-h4c", "LAN_ew_18")
The cities data are from Google Maps (longitude and latitude), expanded by the "Region" entry (sorry, I could not upload the csv file, therefore please see the csv Screenshot). enter image description here Processing in R was done as follows:
Cities <- read.csv("Cities_regions.csv")
Cities_sf <- st_as_sf(Cities, coords = c("Long", "Lat"), crs = 4326)
Cities_crs <- st_transform(Cities_sf, crs = crs(Deutschland, asText=TRUE))
Plotting the map and the city data took place like that:
ggplot(Deutschland) +
geom_sf(fill="#D9D9D9", col="#A6A6A6", lwd=0.1) +
geom_sf(data = Cities_crs, size = 1, col = "black") +
coord_sf()
Here is now where I am stuck since geom_encircle requires X and Y aesthetics that I could not specify correctly so far. Do you have a hint?
Best regards, Christoph