I am currently looking at the response of simulated catchment flow to four climate variables: T, RH, Rs and uz. I would like to construct some 'response surfaces' for my flow to two of the variables, T and Rs, with different combinations of the ranges of Rs and uz i.e. response of flow to T and Rs conditioned on RH and uz.
However there seems to be no functions in lattice that can be used construct surface with 2 conditioning variables, or it's like I've been using them incorrectly. For example I have tried levelplot() but it gave me a blank plot:
# 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")))
So I manually divided the ranges of Rs and uz into intervals and trying to use filled.contour to construct surfaces for each combination of the intervals of Rs and uz.
And here the code I have developed - sorry for the length as I'm still developing my coding skills:
# 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")))
And these seem to give me nice individual surface plots as below but without the bars on the top to indicate the levels of conditioning variables (like you would see on the panels of a standard surface plots generated using lattice - so I am struggling to combine them together and with these bars showing conditioning variables.
Any help would be greatly appreciated! :)