Hi, I'd like to use a custom color sequence (black - low values, green - high values) in am image() plot. While I can specify colors (say a sequence of grays) to the col argument, the ordering is getting messed up. I have two questions: 1. How can I get a sequence of say 256 colors starting from black and ending in green? 2. How is this specified to image() such that it uses the colors in the proper ordering? Thanks, -- Rajarshi Guha NIH Chemical Genomics Center [[alternative HTML version deleted]]
Rajarshi Guha asked:> > Hi, I'd like to use a custom color sequence (black - low values, > green - high values) in am image() plot. While I can specify colors > (say a sequence of grays) to the col argument, the ordering is > getting messed up. I have two questions: > > 1. How can I get a sequence of say 256 colors starting from black > and ending in green? > 2. How is this specified to image() such that it uses the colors in the > proper ordering? >Does image(x, y, z) (whatever are the x, y and z) work correctly? If so, probably this is what you want: image(x, y, z, nlevels=256, col=rgb(0, seq(0, 1, length=256), 0)) Explanation: rgb(0, seq(0, 1, length=256), 0) creates a vector of colours that begin with "black" = "#00000" and ends up with "green" = "#00FF00". Parameter nlevels = 256 forces the image to use all colours. Alberto Monteiro
On 10/17/2009 01:25 AM, Rajarshi Guha wrote:> Hi, I'd like to use a custom color sequence (black - low values, green - > high values) in am image() plot. While I can specify colors (say a sequence > of grays) to the col argument, the ordering is getting messed up. I have two > questions: > > 1. How can I get a sequence of say 256 colors starting from black and ending > in green? > 2. How is this specified to image() such that it uses the colors in the > proper ordering? >Hi Rajarshi, Adding to what Albert wrote, if you mean that you want black to gray and then gray to green, you can get it by creating two sequences of colors and then joining them together: ccolors<-c(rgb(seq(0,0.5,length.out=128), seq(0,0.5,length.out=128),seq(0,0.5,length.out=128)), rgb(seq(0.5,0,length.out=128),seq(0.5,1,length.out=128), seq(0.5,0,length.out=128))) image(...,col=ccolors,...) See the examples in "color2D.matplot" for more information. Jim