Dear R-helpers, I'm plotting geophysical data in the form of contours using "filled.contour". The display would be much more effective if the areas with negative values could be color coded by -- say -- "cold colors" in the range of blue to green, and conversely the areas with positive values got plotted with "warm colors", from yellow to red. Right now if I use a palette spanning the spectrum I need the entire range is associated with the actual range of the data, which can be positively or negatively skewed, and as a result the position of the zero is totally arbitrary. I'm wondering if someone out there has come up with a clever way to set the color scale accordingly, as a function of the actual range of the values in the matrix that is being plotted. Ideally, it would be neat to still use the entire spectrum, but sampling differently the cold and warm subsets accordingly to the extent of the negative and positive values in the data. Also, when I try to play around in an ad hoc fashion with the palette I often get funny results in the legend, with color-scale wrapping or blank cells at one of the extremes. I cannot hack effectively the code of the filled.contour function, obviously... Thank you in advance for your help & happy new year claudia tebaldi -- Claudia Tebaldi ISSE/CGD/IMAGe http://www.image.ucar.edu/~tebaldi currently visiting Center for Environmental Science and Policy Stanford University tel: (650) 724-9261 skype: claudia.tebaldi
Hi Claudia, It's quite easy to do this using ggplot, although you get exactly the same appearance as filled.contour (hopefully in the next version). Have a look at ggtile and scgradient. Regards, Hadley On 1/4/07, Claudia Tebaldi <tebaldi at rap.ucar.edu> wrote:> Dear R-helpers, > > I'm plotting geophysical data in the form of contours using > "filled.contour". The display would be much more effective if the areas > with negative values could be color coded > by -- say -- "cold colors" in the range of blue to green, and conversely > the areas with positive values got plotted with "warm colors", from yellow > to red. > Right now if I use a palette spanning the spectrum I need the entire range > is associated with the actual range of the data, which can be positively > or negatively skewed, and as a result the position of the zero is totally > arbitrary. > I'm wondering if someone out there has come up with a clever way to set > the color scale accordingly, as a function of the actual range of the > values in the matrix that is being plotted. Ideally, it would be neat to > still use the entire spectrum, but sampling differently the cold and warm > subsets accordingly to the extent of the negative and positive values in > the data. > > Also, when I try to play around in an ad hoc fashion with the palette I > often get funny results in the legend, with color-scale wrapping or blank > cells at one of the extremes. I cannot hack effectively the code of the > filled.contour function, obviously... > > > Thank you in advance for your help > & happy new year > > claudia tebaldi > > > > > > > > > > > > -- > Claudia Tebaldi > ISSE/CGD/IMAGe > http://www.image.ucar.edu/~tebaldi > > currently visiting > Center for Environmental Science and Policy > Stanford University > tel: (650) 724-9261 > skype: claudia.tebaldi > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Richard M. Heiberger
2007-Jan-05 03:39 UTC
[R] color of opposite sign values in filled.contour
Get the RColorBrewer package from CRAN Description: The packages provides palettes for drawing nice maps shaded according to a variable.
Claudia Tebaldi wrote:> Dear R-helpers, > > I'm plotting geophysical data in the form of contours using > "filled.contour". The display would be much more effective if the areas > with negative values could be color coded > by -- say -- "cold colors" in the range of blue to green, and conversely > the areas with positive values got plotted with "warm colors", from yellow > to red. > Right now if I use a palette spanning the spectrum I need the entire range > is associated with the actual range of the data, which can be positively > or negatively skewed, and as a result the position of the zero is totally > arbitrary. > I'm wondering if someone out there has come up with a clever way to set > the color scale accordingly, as a function of the actual range of the > values in the matrix that is being plotted. Ideally, it would be neat to > still use the entire spectrum, but sampling differently the cold and warm > subsets accordingly to the extent of the negative and positive values in > the data. > > Also, when I try to play around in an ad hoc fashion with the palette I > often get funny results in the legend, with color-scale wrapping or blank > cells at one of the extremes. I cannot hack effectively the code of the > filled.contour function, obviously... > >Hi Claudia, Have a look at color.scale in the plotrix package. You can specify quite a variety of different color ranges into which your numeric values will be transformed. If you want different color ranges for positive and negative values, you can calculate them separately. Here's an example using blue to green for negative values and yellow to red for positive: testval<-c(-3,6,-1,8,0,-2,4,10,12) testcol<-rep(0,length(testval)) testcol[testval<0]<-color.scale(testval[testval<0],0,c(0,1),c(1,0)) testcol[testval>=0]<-color.scale(testval[testval>=0],1,c(1,0),0) plot(testval,col=testcol,pch=19) You might also be interested in color.scale.lines Jim
On Thu, 4 Jan 2007, Richard M. Heiberger wrote:> Get the RColorBrewer package from CRAN > > Description: The packages provides palettes for drawing nice maps > shaded according to a variable.The package "vcd" also offers the function diverge_hcl() that constructs diverging palettes (based on HCL colors) particularly aimed at filled.contour() or image() plots. See http://epub.wu-wien.ac.at/dyn/openURL?id=oai:epub.wu-wien.ac.at:epub-wu-01_abd for some more background information. Z
Dear all, especially those of you that kindly provided suggestions yesterday, I was not asking for cool palettes -- even if I now appreciate the pointers -- but I was asking for a way to make the 0 level of a filled contour plot correspond to the neutral color in the color scale when the range of my values is not symmetrical around zero...without hacking into the filled.contour function (which I'm not able to do succesfully). I couldn't get the ggplot package suggested because I'm not running MAC OSX 10.4, unfortunately...all the other suggestions didn't provide a way out...at least that I could recognize. Thanks again -- last time I bother you I promise! claudia tebaldi -- Claudia Tebaldi ISSE/CGD/IMAGe http://www.image.ucar.edu/~tebaldi currently visiting Center for Environmental Science and Policy Stanford University tel: (650) 724-9261 skype: claudia.tebaldi -- Claudia Tebaldi ISSE/CGD/IMAGe http://www.image.ucar.edu/~tebaldi currently visiting Center for Environmental Science and Policy Stanford University tel: (650) 724-9261 skype: claudia.tebaldi