我正在尝试制作地图(附图片),但希望将我的shapefile叠加到地图上。我目前无法让它工作 - shapefile的代码在最后,我已经包含了shapefile的摘要,以防这是有用的 - 我不确定它是坐标系的格式还是更简单的东西?我还附加了一个数据文件的链接,以使其可重现(https://onedrive.live.com/redir?resid=9E74848E574367C6!2648&authkey=!AGApYipxXqSwZw4&ithint=folder%2ccsv)
lon.data <- c(28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5) # Define the longitudinal data for matrix creation
lat.data <- c(-4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5) # Define the latitudinal data for matrix creation
nlons <- length(lon.data)
nlats <- length(lat.data)
x.limit <- range(lon.data, na.rm=T)
y.limit <- range(lat.data, na.rm=T)
Avg.Matrix.1 <- matrix(NB.GRACE[,123], nrow=nlons, ncol=nlats, byrow=F) # Form a matrix for 2003-2012 gridded averages
Avg.Matrix.1[Avg.Matrix.1 > 30] <- 30 # Reports all TWS anomalies > 30 and 30cm
Avg.Matrix.1[Avg.Matrix.1 < -30] <- -30 # Reports all TWS anomalies < -30 and -30cm
tws.range <- c(-5,5)
par(mar=c(7.8,6.3,0.4,6.3), mgp=c(1.5,0.5,0))
image(lon.data, lat.data, Avg.Matrix.1, xlim=x.limit, ylim=y.limit, zlim=tws.range, asp=1, axes=F,
cex.axis=0.85, col=rev(tim.colors(60)), xlab="Longitude", ylab="Latitude", cex.lab=0.8)
axis(1, at=seq(29, 36, by=1), labels=c("29°","30°","31°","32°","33°","34°","35°","36°"), cex.axis=0.8)
axis(2, at=seq(-4, 4, by=1), labels=c("-4°","-3°","-2°","-1°","0°","1°","2°","3°","4°"), cex.axis=0.8, las=1)
image.plot(zlim=tws.range, col=rev(tim.colors(50)), axis.args=c(cex.axis=0.9), legend.only=T)
grid(lwd=0.75, col="gray60", lty=1)
abline(h=c(-4,-3,-2,-1,0,1,2,3,4), v=c(29,30,31,32,33,34,35,36), col="gray60", lty=3, lwd=0.5)
box(lwd=1.5)
LVB.Waterbodies <- readShapeLines("Victoria Water Areas.shp")
map(LVB.Waterbodies, add=TRUE, col=1)
LVB.Waterbodies
class : SpatialLinesDataFrame
features : 1
extent : 133171.2, 761398.7, -418201.5, 55283.06 (xmin, xmax, ymin, ymax)
coord. ref. : NA
variables : 3
names : Id, Area, iub
min values : 0, 0, 69946.845771
max values : 0, 0, 69946.845771
编辑**这是我收到的错误消息:
map(LVB.Waterbodies, add=TRUE, col=1)
Error in `[.data.frame`(x@data, i, j, ..., drop = FALSE) :
undefined columns selected
不显示shapefile(附加图片)。我可以使用plot(LVB.Waterbodies, col=1)
来显示它,但这不会将其添加到原始图中,而是作为单独的图...如您所说,这可能是对齐的?