问题
I am trying to create a map of the bathymetry of the region around Faroe (only the sea bottom). I am using lattice and wireframe function. So I did:
depthfaroe <- getNOAA.bathy(lon1 = -11, lon2= -2, lat1 = 60, lat2 = 63, resolution = 1) %>%
fortify()
depthfaroeNeg <- depthfaroe
depthfaroeNeg$z[which(depthfaroeNeg$z > 0)] <- 0 #I remove the detail on the land
depthfaroe <- as.bathy(depthfaroeNeg)
wireframe(unclass(depthfaroe), shade = T, aspect = c(0.6, 0.1),
screen = list(z = 0, x = -20),
par.settings = list(axis.line=list(col="transparent")),
zoom = 1.5,
par.box=list(col=NA),
col.regions = colorRampPalette(c("blue", "pink"))(100)
)
However, impossible to make the col.region setting work. Moreover, I would like to color in grey the region with a depth of 0. So basically, two question:
- why the col.region parameter is not working (Manually defining the colours of a wireframe seems not to work)
- how to make a gradient of color AND for one particular z have a special color (e.g. for the z = 0)?
Thanks a lot in advance for your advise
Charlotte
回答1:
Thanks to the package developper, I found an answer:
ramp.fun <- colorRamp(c("darkblue", "cadetblue1", "burlywood4"))
custom.palette <- function(irr, ref, height, rampfun = ramp.fun)
{if(height != 1) {
## convert height to color using rampfun and map to HSV space
h.hsv <- rgb2hsv(t(rampfun(height)))
## reduce 'V' (brightness): multiply by irradiance
toReturn <- hsv(h = h.hsv["h",],
s = h.hsv["s",],
v = irr * h.hsv["v",])
} else {
toReturn <- "grey"
}
return(toReturn)
}
xlim <- c(-35, 10)
ylim <- c(55, 70)
m <- map_data("worldHires", xlim = xlim, ylim = ylim)
depth <- getNOAA.bathy(lon1 = xlim[1], lon2= xlim[2], lat1 = ylim[2], lat2 = ylim[1], resolution = 2) %>%
fortify()
depthNeg <- depth
depthNeg$z[which(depthNeg$z > 0)] <- 0
depth <- as.bathy(depthNeg)
wireframe(unclass(depth), shade = T,
aspect = c(0.6, 0.1),
screen = list(z = 0, x = -20),
par.settings = list(axis.line=list(col="transparent")),
zoom = 1.5,
par.box=list(col=NA),
col='transparent',
shade.colors.palette = custom.palette
)
I hope it will help :)
Cheers!
Cha
来源:https://stackoverflow.com/questions/50230598/r-lattice-wireframe-color