【问题标题】:R lattice wireframe colorR格线框颜色
【发布时间】:2018-05-08 09:43:08
【问题描述】:

我正在尝试绘制法罗周围地区(仅海底)的测深地图。我正在使用格子和线框功能。所以我做了:

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)
)

但是,无法使 col.region 设置起作用。此外,我想将深度为 0 的区域涂成灰色。 所以基本上,两个问题:

  1. 为什么 col.region 参数不起作用(Manually defining the colours of a wireframe 似乎不起作用)
  2. 如何为某个特定的 z 制作颜色渐变并且具有特殊颜色(例如,对于 z = 0)?

非常感谢您的建议

夏洛特

【问题讨论】:

    标签: r lattice


    【解决方案1】:

    感谢包开发者,我找到了答案:

    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
    )
    

    我希望它会有所帮助:)

    干杯!

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2021-04-15
      • 1970-01-01
      • 2021-08-14
      相关资源
      最近更新 更多