使用R的地区/城市的特定国家/地区地图 [英] specific country map with district/cities using R

查看:92
本文介绍了使用R的地区/城市的特定国家/地区地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一些特定的国家/地区地图,例如孟加拉国,不丹等,其地区/城市位于R.例如,我可以使用以下代码行绘制美国地图.有没有这样的 library/package 可以给我任何国家/地区提供其城市/地区/省的地图?任何线索表示赞赏.

 库(地图)状态<-map_data(状态") 

解决方案

您可以从以下网站下载任何国家的shapefile

 #使用ggplot2绘图ggplot()+geom_sf(data = sf,aes(fill = NAME_2))+ theme(legend.position ="none") 

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

解决方案

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

这篇关于使用R的地区/城市的特定国家/地区地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆