我想制作多米尼加共和国的等值线图。至于边界,我需要的是该国内的州。多米尼加共和国R等值线图
我曾尝试以下:
map <- GetMap('Dominican Republic' , zoom = 8 ,)
PlotOnStaticMap(map)
PlotPolysOnStaticMap(map , polys)
我想制作多米尼加共和国的等值线图。至于边界,我需要的是该国内的州。多米尼加共和国R等值线图
我曾尝试以下:
map <- GetMap('Dominican Republic' , zoom = 8 ,)
PlotOnStaticMap(map)
PlotPolysOnStaticMap(map , polys)
你可以做到这一点没有RGoogleMaps。加州大学戴维斯分校的各个区域都有shapefile & RData文件。下面的注释代码:
theme_map
可以以类似的方式利用其他实际形状文件:
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([email protected]$ID_1,
[email protected]$NAME_1,
value=sample(100, nrow([email protected])))
# 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,其目的是简化每一个国家的管理等级1的地图等值线的创建在世界R.
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)
你_need_使用RGoogleMaps? – hrbrmstr
不一定。我发现它们很有趣 – Illya