R lattice wireframe color

寵の児 提交于 2021-01-28 12:02:24

问题


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:

  1. why the col.region parameter is not working (Manually defining the colours of a wireframe seems not to work)
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!