【发布时间】:2018-07-27 16:35:40
【问题描述】:
我在堆栈中有 3 个不同的栅格。我需要绘制一个面板图并在每个面板上添加不同的 shapefile。到目前为止,我设法做到了以下几点;
## read the libraries
library(raster)
library(rgdal)
library(sp)
library(rworldmap)
library(OceanView)
##random raster object
r <- raster(ncol=40, nrow=20)
r[] <- rnorm(n=ncell(r))
# Create a RasterStack object with 3 layers
s <- stack(x=c(r, r*2, r**2))
##coordinate system
wgs<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
##reading the additional shape files
w <- spTransform(getMap(), wgs)
poly <- list(list("sp.lines", as(w, 'SpatialLines'), lwd =
0.5,col="black"))
##plotting with spplot
plot(spplot(s,layout=c(3,1),sp.layout=poly,
colorkey =list(space = "right"),
names.attr = c("a","b","c")))
到目前为止,我绘制了 3 个栅格,上面覆盖了一个 shapefile。现在我需要在面板图上分别绘制 3 个不同的轮廓。并且还需要在每个图上绘制风速箭头。我知道要做到这一点,我需要使用 contour() 和 quiver() 函数。但是,我无法绘制这些。
## different raster stack for the contour plot
s1 <- stack(x=c(r/2, r*10, r**5))
##differnt wind components
lat= matrix(rep(seq(-90,90,length.out=20),each=20), ncol=20, byrow=TRUE)
lon=matrix(rep(seq(-180,180,length.out=20),each=20), ncol=20, byrow=F)
u=matrix(rep(sample(seq(-2,2,length.out=1000),20),each=20), ncol=20, byrow=TRUE)
v=matrix(rep(sample(seq(-2,2,length.out=1000),20),each=20), ncol=20, byrow=TRUE)
##plot the arrows
quiver2D(u = u,v=v,x = lon, y = lat,add=T,type="simple")
谁能帮我解决这个问题?任何帮助将不胜感激。
【问题讨论】:
-
我不清楚“面板图”应该是什么,也无法在任何这些包中找到函数
quiver(或quiver2D)。 -
@42- 哦,对不起,我没有把所有的库都放在那里。通过面板图我的意思是说一个有 3 列和 1 行的图。我不想单独绘制每个栅格,而是想将它们组合在一个图中,并且 spplot 具有此 layout=c(3,1) 的功能。关于箭头图,有不同的包,如 pracma::quiver 或 OceanView::quiver2D 做同样的工作。
-
所以您希望在单个输出页面上绘制多个图,或许以“横向”格式呈现?我现在从
quiver2D调用的checkinput函数中得到一个错误。说'x' not compatible with u or v,可能是因为你设置set.seed()后没有测试你的随机值? -
我已经尝试了几次,但仍然无法让第二个块中的代码正常运行。
-
@42- 错误是由于行和列不匹配。我纠正了它,它现在应该可以工作了。如果你能在没有错误的情况下绘图,你能告诉我吗?
标签: r raster contour lattice sp