Skip to content
Back to formatted view

Raw Message

Message-ID: <4BDEAEA1.80600@bitwrit.com.au>
Date: 2010-05-03T11:08:17Z
From: Jim Lemon
Subject: help with color scale
In-Reply-To: <4BDDC029.9070706@ouce.ox.ac.uk>

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