[R-SIG-Mac] lattice-wireframe change colours

David Winsemius dwinsemius at comcast.net
Thu Feb 24 20:56:00 CET 2011


On Feb 24, 2011, at 1:01 PM, James Platt wrote:

> Hi all,
>
> I'm trying to plot a 3D graph using wireframe, and I want to colour  
> the graph dependent on z axis values.  my z axis range is 0 - 2.  
> Basically what I want is to colour from various points different  
> colours. so say 1.4-2 would be blue, 0.4-1.4 red 0 - 0.4 green or  
> whatever colours.
>
>
> data.m = as.matrix(read.table("data.txt", sep='\t', header=T))[,-1]
> library(lattice)
> wireframe(data.m,aspect = c(0.3), shade=TRUE, screen = list(z = 0, x  
> = -45), light.source = c(0,0,10), distance =  
> 0.2,zlab="Freq",xlab="base",ylab="Fragment")
>
>
> That is what I have so far, this just uses the rainbow colour, but i  
> want to assign specific colours to specific regions. I have tried to  
> look through the documentation but its not terribly clear to me.

Following the advice in help(wirefrane) you need to look at the  
levelplot section for advice re: a proper specification to colorkey  
and follow the appropriate links in the help pages. Whether your data  
is a proper input to wireframe cannot be determined from the included  
information, although I suppose your reported success suggests it is.

This is an untested (since there was nothing to test) wild-assed guess  
after reading the material I pointed to:

wireframe(data.m,aspect = c(0.3), shade=TRUE, screen = list(z = 0, x =  
-45),
    light.source = c(0,0,10), distance =  
0.2,zlab="Freq",xlab="base",ylab="Fragment",
    col=level.colors(x, at = do.breaks(range(data.m), 30),
                     col.regions = colorRampPalette(c("red", "white",  
"blue")(30))
       )

(Also not a Mac question so is on the wrong list.)

--

David Winsemius, MD
West Hartford, CT



More information about the R-SIG-Mac mailing list