Below is a 3D curve using the R function persp3d and specifying the colors.
library(rgl)
y = seq(-5,25,by=0.1)
x = seq(5,20,by=0.2)
NAs <- rep(NA, length(x)*length(y))
z <- matrix(NAs, length(x), byrow = T)
for(i in seq(1,length(x))) {
for(j in seq(1,length(y))) {
val = x[i] * y[j]
z[i,j] = val
if(z[i,j] < 0.02) {
z[i,j] = NA
}
}
}
col <- rainbow(length(x))[rank(x)]
open3d()
persp3d(x,y,z,color=col,xlim=c(5,20),ylim=c(5,10),axes=T,box=F,xlab="X Axis",ylab="Y Axis",zlab="Z Axis")
And it produces this image:

In the current version, for an x value of 15, the color is blue regardless of the z value. But I’d like it so that high z values are dark blue whereas low z values are light blue, if that makes sense. How can I do something like this, so that color not only distinguishes x values but also z values?
You will have to play around with colors in HSV format rather than RGB format for this. It’s easier that way I think.
See my sample code below.
Create unique color for each value of x.
Create grid of colors by repeating
collength(y)timesThis should give following. You can play around scaling of saturation or value of colors to get desired “lightness” or “darkness” of shades.