[R-sig-Geo] fix color scale

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Oct 29 11:02:36 CEST 2010


On Thu, Oct 28, 2010 at 8:12 PM, Peter Larson <pslarson2 at gmail.com> wrote:
> Hello!
>
> I have a problem.
>
> I am using IDW to interpolate a daily series of geospatial
> observations. Thus, I want to produce a large number of sequential
> maps.
>
> I want them to all represent the same color scale. Is there any way to
> fix the color scale so that it is the same for all the plots?
>

 I have a solution!

 It's called my colourscheme package:

https://r-forge.r-project.org/projects/colourscheme/

 you create a colourscheme function that maps values to colours, and
then apply that function to the data you want to plot.

For example:

rs = rampInterpolate ( limits =c(-2 , 2),
               ramp = c("red", " yellow ", " blue "))

creates a colour scheme function that maps -2 to red, 0 to yellow, and
2 to blue with continuous RGB interpolation between those values, and
NA elsewhere:

 rs(seq(-3,3,len=10))
 [1] NA          NA          "#FF2A00FF" "#FF8000FF" "#FFD400FF" "#D5D52AFF"
 [7] "#808080FF" "#2B2BD4FF" NA          NA

 plot(seq(-3,3,len=100),col=rs(seq(-3,3,len=100)),pch=19)

 So whatever your data, if you do:

 plot(x,y,col=rs(z))

 you'll get the same colour mapping: -2 is red, +2 is blue.

Barry



More information about the R-sig-Geo mailing list