Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed color for specific value

Tags:

r

colors

I am trying to make a temperature map, all works fine but I don't know how to have a fixed color palette.

Actually I have this :

rgb.palette <- colorRampPalette(c("blue","green","yellow","orange","red"), 
                                space = "Lab")

image.plot(akima.smooth, 
           col = rgb.palette(NBR.COLORS), 
           main=main_title, 
           horizontal=TRUE,
           axes=TRUE)

This solution works but the colors which are painted are always from blue to red.

For example if the lowest temperature on the map is -10°C the color will be blue, but in another map if the lowest temperature is +25°C that color will be blue too.

How can I define a fixed color panel such as :

-30°C => blue
-20°C => light blue
-10°C => dark green
  0°C => green
 10°C => yellow

If in map 1 lowest temperature is -20 I want "light blue" and in map 2 if lowest temperature is 10°C I want "yellow" color.

like image 319
Vince Avatar asked May 03 '12 17:05

Vince


People also ask

How do I assign a color to a variable in R?

In R, colors can be specified either by name (e.g col = “red”) or as a hexadecimal RGB triplet (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the RColorBrewer package.

What is fixed color?

The only setting you can change is the color of the values. In Fixed color mode, you can still add rules to the color scheme, and the rules will be applied to the column you have selected. In the example above, the scatter plot is colored by the column Sales.


1 Answers

If this is fields:::image.plot() then see the arguments to function ?image. In particular the breaks argument is required to set the values for the boundaries of the cut points used to break the input data into the classes for plotting.

The problem you are seeing is that if you don't set breaks then the colour palette is being applied to the range of the input data. If you set breaks then the colour palette is mapped across the full range you want and the data allocated to the groups, and hence the colours, defined by the break points.

I haven't included an example in case this is not fields:::image.plot()

like image 125
Gavin Simpson Avatar answered Sep 30 '22 13:09

Gavin Simpson