specific country map with district/cities using R

后端 未结 1 1780
深忆病人
深忆病人 2021-01-27 09:14

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 follo

相关标签:
1条回答
  • 2021-01-27 09:53

    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")
    

    0 讨论(0)
提交回复
热议问题