How to plot different district names on shapefile in R?

691 views Asked by At

I have shapefile of my study area "Gilgit Baltistan". I want to plot names of districts on map(shapefile)

Using this code I can plot study area map. How can I show names of districts on this map?

library(mapdata)
library(prettymapr)
library(ggplot2) # For map design
library(ggspatial) # For map design
library(ggrepel)  # For map design
library(patchwork) # For multiple map layout
library(raster) # For manage raster data
library(sf) # For manage vector data.
library(sp)

GB<-readOGR("GBdistrict.shp")
plot(GB)
1

There are 1 answers

0
RobertoSupe On

hope this works

 labels<-cbind(GB,st_coordinates(st_centroid(GB$geometry))) #get the x and y for the names

ggplot()+
  geom_sf(data=GB)+
  geom_text(data=labels,aes(label=NAME_1,x=X,y=Y),colour="black")

NAME_1 is the variable with your names, change it if needed.