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. Sam -- View this message in context: http://www.nabble.com/setting-color-ranges-tp15489086p15489086.html Sent from the R help mailing list archive at Nabble.com.
Hi Sam, You might find it easier to use ggplot2 to do this. See http://had.co.nz/ggplot2/geom_tile.html for some examples. Hadley On Thu, Feb 14, 2008 at 2:59 PM, samsr <sameet.sreenivasan at gmail.com> 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. > > Sam > -- > View this message in context: http://www.nabble.com/setting-color-ranges-tp15489086p15489086.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/
On Thu, 14 Feb 2008, 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.Look at the function diverge_hcl() in package "vcd" which provides diverging palettes. You can find several examples in example("diverge_hcl", package = "vcd") vignette("hcl-colors", package = "vcd") Further background information is available in this technical report by Kurt Hornik, Paul Murrell and me http://epub.wu-wien.ac.at/dyn/openURL?id=oai:epub.wu-wien.ac.at:epub-wu-01_c87 Best, Z> Sam > -- > View this message in context: http://www.nabble.com/setting-color-ranges-tp15489086p15489086.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >
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. x<-matrix(rnorm(100),nrow=10) 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