I am trying to plot the image of this raster file. The colour of the legend was like this: low values with red colour and high values with green.
But normally red colour is associated with high values. That’s why I then used rev to reverse the colour of the legend. However I got something different. Is there another function to reverse the colour of the legend and keep the colours as they are.
require(raster)
require(fields)
r = raster(y)
extent(r) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90))
plot(r, col = rainbow(20, s = 1, v = 1, start = 0,
end = 1),lab.breaks=seq(0,0.6,0.05),
breaks=seq(0,0.6,0.05), zlim=c(0.0,0.6),horizontal = TRUE,
xlab="Longitude", ylab="Latitude",legend.shrink = 0.9,
legend.width = 1.2)
then I used this which gave me:
plot(r, col = rev(rainbow(20, s = 1, v = 1, start = 0, end = 1)),
lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude",
ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)
Obviously you didn’t check the colors.
But not all 20 are used, you only use 12 of them, so:
should give you the plot you want. After all, you have 13 break values, so only 12 categories. Which means you could have done: