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.
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With