1

I am trying to insert an RColorBrewer palette to visualize an elevation raster in R using the rasterVis function plot3D. The rasterVis reference document shows the following parameters:

plot3D(x, maxpixels=100000, zfac=1, drape=NULL, col, rev=FALSE, adjust=TRUE, ...)

However, when I use col= I get the following error:

Error in col(zlen) : 
  a matrix-like object is required as argument to 'row/col'

When I use color= I get:

Error in f(...) : 
  formal argument "color" matched by multiple actual arguments

I've also tried this:

color.palette = brewer.pal(11, "PRGn")

which renders the 3D-plot, but uses the default color palette.

This article does not provide a solution. Nor have I found anything useful on GISSE or StackOverflow:

Any suggestions, assistance clarifying the errors, or input is much appreciated.

2

From ?plot3D:

Arguments

...

col: A color palette generating function such as rainbow, heat.colors, and topo.colors, or one or your own making

You can use colorRampPalette to generate your own palette function from given colors, e.g.

library("rasterVis")
library("RColorBrewer")
data(volcano)
r <- raster(volcano)
extent(r) <- c(0, 610, 0, 870)
plot3D(r, drape=NULL, zfac=2, col=colorRampPalette(brewer.pal(11, "PRGn")))
0
plot3D(raster,lit=TRUE,specular="black",  
   shininess=5, 
   col=colorRampPalette(rainbow(n=12,v=0.7, s = 0.9,start = 0.5,end=0.85)))

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 2
    Welcome to GIS SE. As a new user, please take the Tour. Answers here should be more than one line of code. This is especially true of new answers to old questions which have been marked as answered. Please Edit this answer to contain an explanation of what you are recommending and why it is different or changed since the accepted answer. – Vince Jul 8 '17 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.