繁体   English   中英

多米尼加共和国的R choropleth地图

[英]R choropleth map of the Dominican Republic

我想作一个多米尼加共和国的choropleth地图。 至于边界,我只需要那个国家的州。

我尝试了以下方法:

map <- GetMap('Dominican Republic' , zoom = 8 , ) 
PlotOnStaticMap(map) 
PlotPolysOnStaticMap(map , polys)

您可以在没有RGoogleMaps的情况下执行此操作。 加州大学戴维斯分校有针对地球上每个区域的shapefile和RData文件。 以下带注释的代码:

  • 下载DR管理员级别1区域的RData SpatialPolygonsDataFrame
  • 抓住我的theme_map
  • 制作样本数据集
  • 为DR绘制带有适当地图投影的Choropleth

您可以类似的方式使用其他实际的shapefile:

library(sp)
library(ggplot2)

# theme_map
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df")

# the DR "shapefile"
download.file("http://biogeo.ucdavis.edu/data/gadm2/R/DOM_adm1.RData", "DOM_adm1.RData")
load("DOM_adm1.RData")

# for plotting with ggplot2
dr_map <- fortify(gadm)


# build some sample data, note that we'll be using
# the polygon "id" for plotting so you'll need that in the
# data frame
set.seed(1492)
choro <- data.frame(id=gadm@data$ID_1,
                    place=gadm@data$NAME_1,
                    value=sample(100, nrow(gadm@data)))

# you can look at the data with this (it won't be shown here)
head(choro)

# plot
gg <- ggplot()

# base map layer
gg <- gg + geom_map(data=dr_map, map=dr_map,
                    aes(x=long, y=lat, map_id=id),
                    fill="white", color="#7f7f7f", size=0.25)

# DR choro layer
gg <- gg + geom_map(data=choro, map=dr_map, 
                    aes(fill=value, map_id=id), 
                    color="#7f7f7f", size=0.25)

# lambert is a gd proj for DR
gg <- gg + coord_map("lambert", lat0=17.5, lat1=20)

# clean up map chart junk
gg <- gg + theme_map()

# move legend
gg <- gg + theme(legend.position="right")

# plot it
gg

在此处输入图片说明

我创建了一个R包choroplethrAdmin1 ,该包旨在简化R中世界上每个国家的管理级别1区域地图的创建。

library(choroplethr)
library(choroplethrAdmin1)

# ?admin1_map just draws an outline
admin1_map("dominican republic")

在此处输入图片说明

要创建一个Choropleth,您需要有一个data.frame,其中包含两列:一列命名区域,一列命名值。 区域必须是地图的名称。

# get a column named region, with the names of the regions
df = get_admin1_regions("dominican republic") 
df$value = 1:nrow(df) # add a column called "value"

# ?admin1_choropleth needs the name of the country and the data
admin1_choropleth(country.name = "dominican republic", df = df)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM