[R-sig-Geo] help with color scale

Jim Lemon jim at bitwrit.com.au
Mon May 3 13:08:17 CEST 2010


On 05/03/2010 04:10 AM, Muhammad Rahiz wrote:
> Hi all,
>
> I hope someone can help me with this.
>
> Given,
>
> library(fields)
> x <- array(rnorm(100),dim=c(50,50))
> image.plot(x)
>
> I want to change the range in the color bar so that the range is from -1
> to 1. I did adjust the image.plot() command to
>
> image.plot(x,zlim=c(-1,1))
>
> but the image shows white spaces.
>
> How can I set the the color scale such that values which are less than -
> 1 are assigned a color e.g. blue and those which are more than 1 are
> assigned red.
>
> In essence, how do I make the color scale to reflect the a certain band
> of values i.e.
>
> color 1 = > 1
> color 2 = 0.9 to 1
> color 3 = 0.8 to 0.9
> ...
> color 8 = -0.8 to -0.9
> color 9 = -0.9 to -1
> color 10 = < -1
>
Hi Muhammad,
The color.scale function in the plotrix package will translate numeric 
values into colors. for example:

imagecolors<-color.scale(x,c(0,1),0,c(1,0))

gives a very simple color scale going from blue at the minimum value to 
red at the maximum. Look at the examples in the color2d.matplot help 
page to see how you can do fancier color mappings.

Jim



More information about the R-sig-Geo mailing list