[R] color scale in rgl plots

Jim Lemon jim at bitwrit.com.au
Sat Jul 7 10:25:04 CEST 2007

David Farrelly wrote:
> Hello,
> I'm trying to make a 3d plot using rgl in which the size and color of
> each point corresponds to certain attributes of each data point. The color
> attribute, let's call it X, is scaled to go from 0 to 1. The
> rainbow(64,start=0.7,end=0.1) palette is perfect for what I want but I
> don't know how to take that palette and pick a color from it based on
> the value of X for a given data point. I'm fairly new to R and any
> suggestions would be greatly appreciated.
> Here's what I do - it's how to do the color mapping that has me stumped.
> plot3d(th1,ph,th2,type='s',size=wd1,col=????(rp1,0,0,1),cex=2,ylab=NULL,xlab=NULL,zlab=NULL,xlim=c(0,1),ylim=c(0,2),zlim=c(0,1),box=TRUE,axes=FALSE)
> I have also tried the more obvious col = rgb(a,b,c,d) where a,b,c,d are
> functions of X but I can't manage to come up with a nice looking color
> scale.
Hi David,
You could check out color.scale in the plotrix package, which does just 


More information about the R-help mailing list