[R-sig-Geo] help with color scale
Muhammad Rahiz
muhammad.rahiz at ouce.ox.ac.uk
Mon May 3 16:43:18 CEST 2010
Thanks Arien & Jim for the useful tips.
I've used both methods suggested but am still not getting the desired
results.
The problem with my actual data is that it contains several extreme
values/outliers.The lab.breaks argument in image.plot() is able to
assign a color to a specific range of value e.g. red = 0.9 to 1. But I
also want to assign a color to any values which are > 1 (e.g. 1.10,
2.15, 25) and < 1 but I'm not able to do that unless i set the color
scale to include the whole range of values - which does not look pretty.
My last resort is to do a small manipulation by using the if/ifelse
function to assign a number to values that beyond a certain threshold
before I plot them.
Muhammad
Jim Lemon wrote:
> 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