R多米尼加共和国的乔洛佩斯地图

R多米尼加共和国的乔洛佩斯地图,r,choropleth,R,Choropleth,我想做一张多米尼加共和国的乔洛佩斯地图。至于边界,我只需要该国境内的州 我尝试了以下方法: map <- GetMap('Dominican Republic' , zoom = 8 , ) PlotOnStaticMap(map) PlotPolysOnStaticMap(map , polys) map您可以在不使用RGoogleMaps的情况下执行此操作。加州大学戴维斯分校有Shapefile&RData文件,用于地球上的每个区域。以下注释代码: 下载DR的管理级别1区域的R

我想做一张多米尼加共和国的乔洛佩斯地图。至于边界,我只需要该国境内的州

我尝试了以下方法:

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

map您可以在不使用RGoogleMaps的情况下执行此操作。加州大学戴维斯分校有Shapefile&RData文件,用于地球上的每个区域。以下注释代码:

  • 下载DR的管理级别1区域的RData空间多边形数据框架
  • 抓取我的主题地图
  • 创建一个示例数据集
  • 为DR绘制具有适当地图投影的choropleth
可以以类似的方式使用其他实际形状文件:

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
库(sp)
图书馆(GG2)
#主题地图
开发工具::源代码https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df")
#“形状文件”博士
下载文件(“http://biogeo.ucdavis.edu/data/gadm2/R/DOM_adm1.RData“,“DOM_adm1.RData”)
加载(“DOM_adm1.RData”)
#用于使用ggplot2打印

dr_map您可以在没有RGoogleMaps的情况下执行此操作。加州大学戴维斯分校(UC Davis)的每个地区都有Shapefile和RData文件。以下注释代码:

  • 下载DR的管理级别1区域的RData空间多边形数据框架
  • 抓取我的主题地图
  • 创建一个示例数据集
  • 为DR绘制具有适当地图投影的choropleth
可以以类似的方式使用其他实际形状文件:

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
库(sp)
图书馆(GG2)
#主题地图
开发工具::源代码https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df")
#“形状文件”博士
下载文件(“http://biogeo.ucdavis.edu/data/gadm2/R/DOM_adm1.RData“,“DOM_adm1.RData”)
加载(“DOM_adm1.RData”)
#用于使用ggplot2打印
dr_map我创建了一个R包,该包旨在简化R中世界上每个国家的管理级别1 choropleth地图的创建

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)

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

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)

您需要使用RGoogleMaps吗?不一定。我刚发现他们很感兴趣你需要使用RGoogleMaps吗?不一定。我只是觉得他们很有趣