我目前正在研究模拟集水流对四个气候变量的响应:T、RH、Rs 和 uz。我想为我的两个变量T 和 Rs的流量构建一些“响应面”,其中Rs 和 uz范围的不同组合,即流量对T 和 Rs的响应以RH 和 uz为条件。
然而,格子中似乎没有可用于构造具有 2 个条件变量的表面的函数,或者就像我一直在错误地使用它们一样。例如,我尝试了 levelplot()但它给了我一个空白图:
# Separate input variables and define range intervals for plotting
deltaT <- as.matrix(x$X$X1)
deltaRH <- as.matrix(x$X$X2)
deltaRs <- as.matrix(x$X$X3)
deltauz <- as.matrix(x$X$X4)
responseQave <- as.matrix(t(yPenman)[,11])
# Use 2 intervals for each conditioning variable with 10% overlap
deltaRHint <- equal.count(deltaRH,number=2,overlap=.1)
deltauzint <- equal.count(deltauz,number=2,overlap=.1)
levelplot(responseQave ~ deltaT * deltaRs | deltaRHint * deltauzint, zlim = c(-20,20),cuts=10, col.regions = colorRampPalette(c("red", "white", "blue")))
因此,我手动将 Rs 和 uz 的范围划分为区间,并尝试使用fill.contour为 Rs 和 uz 区间的每种组合构造曲面。
这里是我开发的代码 - 对不起,因为我仍在发展我的编码技能:
# Extract the boundaries of intervals for each conditioning variable
deltaRHI <- as.matrix(levels(deltaRHint))
deltaRHI <- c(deltaRHI[[1]][1],deltaRHI[[1]][2],deltaRHI[[2]][1],deltaRHI[[2]][2])
deltauzI <- as.matrix(levels(deltauzint))
deltauzI <- c(deltauzI[[1]][1],deltauzI[[1]][2],deltauzI[[2]][1],deltauzI[[2]][2])
# response to T and Rs
# first combination of RH and uz - interpolate irregular data using akima
grid111 <- interp(x = deltaT[deltaRH>deltaRHI[1] & deltaRH<deltaRHI[2] & deltauz>deltauzI[2]],
y = deltaRs[deltaRH>deltaRHI[1] & deltaRH<deltaRHI[2] & deltauz>deltauzI[2]],
z = responseQave[deltaRH>deltaRHI[1] & deltaRH<deltaRHI[2]& deltauz>deltauzI[2]],
duplicate="strip")
filled.contour(x = grid111$x,
y = grid111$y,
z = grid111$z,
xlim = c(0,8), ylim = c(-10,10), zlim = c(-20,20),
levels = c(seq(-20,20,by = 1)),
color.palette = colorRampPalette(c("red", "white", "blue")))
# second combination of RH and uz
grid222 <- interp(x = deltaT[deltaRH>deltaRHI[2] & deltauz>deltauzI[2]],
y = deltaRs[deltaRH>deltaRHI[2] & deltauz>deltauzI[2]],
z = responseQave[deltaRH>deltaRHI[2]& deltauz>deltauzI[2]],
duplicate="strip")
filled.contour(x = grid222$x,
y = grid222$y,
z = grid222$z,
xlim = c(0,8), ylim = c(-10,10), zlim = c(-20,20),
levels = c(seq(-20,20,by = 1)),
color.palette =
colorRampPalette(c("red", "white", "blue")))
# third combination of RH and uz
grid333 <- interp(x = deltaT[deltaRH>deltaRHI[1] & deltaRH<deltaRHI[2] & deltauz>deltauzI[1] & deltauz<deltauzI[2]],
y = deltaRs[deltaRH>deltaRHI[1] & deltaRH<deltaRHI[2] & deltauz>deltauzI[1] & deltauz<deltauzI[2]],
z = responseQave[deltaRH>deltaRHI[1] & deltaRH<deltaRHI[2]& deltauz>deltauzI[1] & deltauz<deltauzI[2]],
duplicate="strip")
filled.contour(x = grid333$x,
y = grid333$y,
z = grid333$z,
xlim = c(0,8), ylim = c(-10,10), zlim = c(-20,20),
levels = c(seq(-20,20,by = 1)),
color.palette =
colorRampPalette(c("red", "white", "blue")))
# fourth combination of RH and uz
grid444 <- interp(x = deltaT[deltaRH>deltaRHI[2] & deltauz>deltauzI[1] & deltauz<deltauzI[2]],
y = deltaRs[deltaRH>deltaRHI[2] & deltauz>deltauzI[1] & deltauz<deltauzI[2]],
z = responseQave[deltaRH>deltaRHI[2]& deltauz>deltauzI[1] & deltauz<deltauzI[2]],
duplicate="strip")
filled.contour(x = grid444$x,
y = grid444$y,
z = grid444$z,
xlim = c(0,8), ylim = c(-10,10), zlim = c(-20,20),
levels = c(seq(-20,20,by = 1)),
color.palette =
colorRampPalette(c("red", "white", "blue")))
这些似乎给了我很好的个人曲面图,如下所示,但顶部没有条形来指示条件变量的水平(就像您在使用格子生成的标准曲面图的面板上看到的那样- 所以我正在努力将它们组合起来连同这些条形图一起显示条件变量。
任何帮助将不胜感激!:)