Re: [R] setting color ranges

From: Jim Lemon <>
Date: Fri, 15 Feb 2008 22:56:06 +1100

samsr wrote:
> Hi,
> I need to plot a matrix using image() such that negative values are easily
> distinguishable from posittive values, while also maintaining a gradation in
> color with magnitude. How can I set ranges for colors in order to achieve
> this. Thanks.
Hi Sam,

This will give you red colors for the negative values, green for positive.

cellcol<-matrix(rep("#000000",100),nrow=10) library(plotrix)
cellcol[x<0]<-color.scale(x[x<0],c(1,0.8),c(0,0.5),0) cellcol[x>0]<-color.scale(x[x>0],0,c(0.7,0.8),c(0.5,0)) image(z=x,col=cellcol)

Jim mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 15 Feb 2008 - 11:53:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Feb 2008 - 13:30:14 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive