0

I have created a surface 3D plot.

library(emdbook)
params <- c(a0=0.387217066,a1=0.328086337,a2=0.004177033,
            p0=1.117997,p1=5.426564,p2=-220.745499)
Age<- as.matrix(seq(0:299)) 
Preci<-as.matrix(seq(from=10, to=3000, by=10))
curve3d(with(as.list(params),
             a0*(Age^a1)*exp(-a2*Age)*
               p0*(1-exp(-exp(-p1)*(Preci-p2)))),
        varnames=c("Age","Preci"),
        xlim=c(0,300),ylim=c(10,3000),
        sys3d="persp", col='gray',
        xlab = "Stand Age", ylab = "Annual precipitation", zlab = "GPP", 
        phi = 25, theta = 40)

However, the colour scale is grey and I would like to have it related to my z-values (GPP). Anyone knows how to do it?

SimonB
  • 670
  • 1
  • 10
  • 25
  • You can define colours using `colorRampPalette` from the `RColorBrewer` package. See this [post](http://stackoverflow.com/questions/20549540/how-to-create-3d-matlab-style-surface-plots-in-r) for instance – horseoftheyear Oct 30 '15 at 14:58

1 Answers1

0
library(emdbook)

jet.colors <-   # function from grDevices package
  colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan",
                     "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
colorzjet <- jet.colors(300) 

params <- c(a0=411.796734040,a1=0.363361894,a2=-0.005016735,
            p0=-3.418487e+05,p1=-3.883484e-06)
Age<- as.matrix(seq(0:299)) 
Preci<-as.matrix(seq(from=10, to=3000, by=10))

curve3d(with(as.list(params),
             a0*(Age^a1)*(exp(-a2*Age))*
               ((p0*(1-exp(-p1*Preci))))),
        varnames=c("Age","Preci"),
        xlim=c(0,300),ylim=c(10,3000),
        sys3d="persp", col=colorzjet[ findInterval(z, seq(min(z), max(z), length=300))],
        xlab = "Stand Age", ylab = "Annual precipitation", zlab = "GPP", 
        phi = 25, theta = 40)
SimonB
  • 670
  • 1
  • 10
  • 25