I am trying to mark my polygons using ggplot in R. I found a theme here in stackoverflow, which, in my opinion, is very close to what I want, except with dots.
Label points in geom_point
I found several methods on the Internet. Now I first need to find the central location of each figure, and then I have to combine these places with the name. Then bind this to the marking function in geom_text ()
ggplot centered names on the map
Since I tried to do this for a long time, I decided to ask a question and I hope that someone here can give me the last impetus to what I want. My build function:
region_of_interest.fort <- fortify(region_of_interest, region = "score") region_of_interest.fort$id <- as.numeric(region_of_interest.fort$id) region_of_interest.fort$id <- region_of_interest.fort$id region_of_interest.fort1 <- fortify(region_of_interest, region = "GM_NAAM") region_of_interest.fort1$id <- as.character(region_of_interest.fort1$id) region_of_interest.fort1$id <- region_of_interest.fort1$id idList <- unique(region_of_interest.fort1$id) centroids.df <- as.data.frame(coordinates(region_of_interest)) names(centroids.df) <- c("Longitude", "Latitude") randomMap.df <- data.frame(id = idList, shading = runif(length(idList)), centroids.df) ggplot(data = region_of_interest.fort, aes(x = long, y = lat, fill = id, group = group)) + geom_polygon() + geom_text(centroids.df, aes(label = id, x = Longitude, y = Latitude)) + scale_fill_gradient(high = "green", low = "red", guide = "colorbar") + coord_equal() + theme() + ggtitle("Title")
This gives me an error: ggplot2 does not know how to handle uneval class data
My details
region_of_interest$GM_NAAM [1] Groningen Haren Ooststellingwerf Assen Aa en Hunze Borger- Odoorn [7] Noordenveld Westerveld Tynaarlo Midden-Drenthe 415 Levels: 's-Gravenhage 's-Hertogenbosch Aa en Hunze Aalburg Aalsmeer Aalten ... Zwolle region_of_interest$score [1] 10 -2 -1 2 -1 -4 -4 -5 0 0
r maps ggplot2 label
Zuenie
source share