我目前正在研究模拟集水流对四个气候变量的响应: 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的范围划分为区间,并尝试使用 filled.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")))
这些似乎给我提供了很好的单个表面图,如下图所示,但顶部没有条形表示调节变量的水平(就像你在使用晶格生成的标准曲面图的面板上看到的那样) em> - 所以我很难将它们组合在一起,并且这些条形显示条件变量。
任何帮助将不胜感激! :)
答案 0 :(得分:0)
我无法告诉您如何使用未提供的数据进行操作,并且您没有通过提供正确的测试数据集来完成我们,但是有一个interaction
函数可以构建一个因子来自两个输入因素。
dat <- data.frame( responseQave =rnorm(32), deltaT=rnorm(32), deltaRs=rlnorm(32), deltaRHint=a,deltazint=b)
print(levelplot(responseQave ~ deltaT * deltaRs | interaction(deltaRHint, deltazint), data=dat))