我正在尝试创建一个选定的加拿大省/地区和选定的美国州的地图.到目前为止,最好的地图似乎是使用GADM数据生成的地图:http://www.gadm.org/
但是,我无法在同一张地图上绘制美国和加拿大的情节,也无法在选定的省/地区和州绘制地图.例如,我对阿拉斯加,育空,西北地区,不列颠哥伦比亚省,阿尔伯塔省和蒙大拿州等地感兴趣.
此外,美国地图似乎沿着国际日期线分开.
有人可以帮我:
也许spplot不允许用户指定投影.我没有看到在spplot帮助页面上选择投影的选项.我知道如何使用地图包中的地图功能选择投影,但这些地图看起来并不好看,我也无法用该功能绘制所需的省/地区和州的子集.
我不知道如何开始添加纬度 - 经度网格.但是,文件'sp.pdf'的第3.2节似乎解决了这个主题.
下面是我到目前为止提出的代码.我已经加载了我偶然发现的每个与地图相关的包,并注释了除省/地区或州边界之外的GADM数据.
不幸的是,到目前为止我只设法绘制了加拿大或美国的地图
library(maps)
library(mapproj)
library(mapdata)
library(rgeos)
library(maptools)
library(sp)
library(raster)
library(rgdal)
# can0<-getData('GADM', country="CAN", level=0) # Canada
can1<-getData('GADM', country="CAN", level=1) # provinces
# can2<-getData('GADM', country="CAN", level=2) # counties
plot(can1)
spplot(can1, "NAME_1") # colors the provinces and provides
# a color-coded legend for them
can1$NAME_1 # returns names of provinces/territories
# us0 <- getData('GADM', country="USA", level=0)
us1 <- getData('GADM', country="USA", level=1)
# us2 <- getData('GADM', country="USA", level=2)
plot(us1) # state boundaries split at
# the dateline
us1$NAME_1 # returns names of the states + DC
spplot(us1, "ID_1")
spplot(us1, "NAME_1") # color codes states and
# provides their names
#
# Here attempting unsuccessfully to combine U.S. and Canada on one map.
# Attempts at selecting given states or provinces have been unsuccessful.
#
plot(us1,can1)
us.can1 <- rbind(us1,can1)
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.到目前为止,我在上面的步骤2 - 4中没有取得任何进展.也许我要求的太多了.也许我应该简单地切换到ArcGIS并尝试该软件.
我已阅读此StackOverflow帖子:
编辑
我现在借用了"应用空间数据分析与R"Bevand等人的电子版.(2008)并从该书的网站下载(或找到)相关的R代码和数据:
我还在这里找到了一些漂亮的GIS相关R代码:
https://sites.google.com/site/rodriguezsanchezf/news/usingrasagis
如果我学习如何实现预期目标,我将在此处发布解决方案.虽然如果我无法完成R中的目标,我可能最终会转移到ArcGIS.
要SpatialPolygons在同一设备上绘制多个对象,一种方法是首先指定要绘制的地理范围,然后使用plot(..., add=TRUE).这将仅向地图添加感兴趣的点.
使用投影(例如,多边形投影)进行绘图需要首先使用包中的spTransform()功能rgdal来确保所有层都在同一投影中.
## Specify a geographic extent for the map
## by defining the top-left and bottom-right geographic coordinates
mapExtent <- rbind(c(-156, 80), c(-68, 19))
## Specify the required projection using a proj4 string
## Use http://www.spatialreference.org/ to find the required string
## Polyconic for North America
newProj <- CRS("+proj=poly +lat_0=0 +lon_0=-100 +x_0=0
+y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
## Project the map extent (first need to specify that it is longlat)
mapExtentPr <- spTransform(SpatialPoints(mapExtent,
proj4string=CRS("+proj=longlat")),
newProj)
## Project other layers
can1Pr <- spTransform(can1, newProj)
us1Pr <- spTransform(us1, newProj)
## Plot each projected layer, beginning with the projected extent
plot(mapExtentPr, pch=NA)
plot(can1Pr, border="white", col="lightgrey", add=TRUE)
plot(us1Pr, border="white", col="lightgrey", add=TRUE)
Run Code Online (Sandbox Code Playgroud)
向地图添加其他功能(例如突出显示感兴趣的管辖区)可以使用相同的方法轻松完成:
## Highlight provinces and states of interest
theseJurisdictions <- c("British Columbia",
"Yukon",
"Northwest Territories",
"Alberta",
"Montana",
"Alaska")
plot(can1Pr[can1Pr$NAME_1 %in% theseJurisdictions, ], border="white",
col="pink", add=TRUE)
plot(us1Pr[us1Pr$NAME_1 %in% theseJurisdictions, ], border="white",
col="pink", add=TRUE)
Run Code Online (Sandbox Code Playgroud)
结果如下:

使用投影时添加网格线足够复杂,我认为它需要另一个帖子.看起来好像@Mark Miller在下面添加了它!