问题
I am trying to draw some specific countries map such as, Bangladesh, Bhutan etc. with its district/cities in R. As an example, I can draw US map using the following lines of codes. Is there any such library/package
that can give me any countries map with its cities/district/province? Any clue is appreciated.
library(maps)
states <- map_data("state")
回答1:
You can download shapefile of any country from the following website https://www.diva-gis.org/gdata Then read and plot them in R using following code
library(sf)
library(ggplot2)
library(rgdal)
library(rgeos)
#Reading the shapefiles
sf <- st_read(dsn="C:\\Users\\nn\\Desktop\\BGD_adm", layer="BGD_adm2")
shape <- readOGR(dsn="C:\\Users\\nn\\Desktop\\BGD_adm", layer="BGD_adm2")
#To view the attributes
head(shape@data)
summary(sf)
#Plotting the shapefile
plot(shape)
plot(sf)
#Plotting the districts only
plot(sf["NAME_2"], axes = TRUE, main = "Districts")
#Plotting Using ggplot2
ggplot() +
geom_sf(data = sf, aes(fill = NAME_2)) + theme(legend.position = "none")
来源:https://stackoverflow.com/questions/61182881/specific-country-map-with-district-cities-using-r