Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R的地区/城市的特定国家/地区地图_R_Ggplot2_Ggmap - Fatal编程技术网

使用R的地区/城市的特定国家/地区地图

使用R的地区/城市的特定国家/地区地图,r,ggplot2,ggmap,R,Ggplot2,Ggmap,我正在尝试绘制一些特定的国家地图,如孟加拉国、不丹等,其地区/城市位于R。例如,我可以使用以下代码行绘制美国地图。有没有这样的图书馆/软件包可以给我提供任何城市/地区/省的国家地图?任何线索都将不胜感激 library(maps) states <- map_data("state") 您可以从以下网站下载任何国家/地区的shapefile 然后使用下面的代码在R中读取并绘制它们 library(sf) library(ggplot2) library(rgdal) library(rg

我正在尝试绘制一些特定的国家地图,如孟加拉国、不丹等,其地区/城市位于R。例如,我可以使用以下代码行绘制美国地图。有没有这样的图书馆/软件包可以给我提供任何城市/地区/省的国家地图?任何线索都将不胜感激

library(maps)
states <- map_data("state")

您可以从以下网站下载任何国家/地区的shapefile 然后使用下面的代码在R中读取并绘制它们

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

这太棒了。谢谢@BappaDas,但是,使用ggplot2,第二个图给了我一个错误:“st_normalize”不是从“namespace:sf”导出的对象,知道我到底出了什么问题吗?请将R更新到新版本,然后安装新的sf版本。不要忘记通过单击√ 下面是向上投票或向下投票按钮。
#Plotting Using ggplot2
ggplot() + 
  geom_sf(data = sf, aes(fill = NAME_2)) + theme(legend.position = "none")