Please look at the color legend of the image:

enter image description here This image was plotted in ferret program, which has different breaks, like

  • 0-3 with 0.5 interval,
  • 3-9 with 3 interval,
  • 9-10 with 1 interval,
  • 10-20 with 2 interval and
  • 20-70 with 50 interval.

The legend scale was uniformly graduated but labelled as per breaks given. Can we get such legends in R 'Raster - plot'? or any other packages in R?

I have tried in R (raster) and got this image:

enter image description here

In this, the legend is not looking good. I need the a legend like in first image.

The R codes I used are following,

data=raster("dfile.nc") # MODIS-AQUA satellite data
breakpoints=c(0:0.2, 0.21:2,2.01:5,15)
colpatt=rev(colorRampPalette(c("red", "orange", "blue"))(6))
plot(data,breaks=breakpoints, col=colpatt)
  • What do you expect that breakpoints vector to look like? For example 0:0.2 is just 0. The full result is: 0.00 0.21 1.21 2.01 3.01 4.01 15.00 – Spacedman May 16 at 13:49
  • Hi @Karnan, check this useful answer: gis.stackexchange.com/a/17374/80215 – aldo_tapia May 16 at 14:41
  • @Spacedman, the second figures are indicating chlorophyll (chl) concentration. In open oceans, chl concentration will be <0.4µg/L which indicates oligotrophic condition. In coastal waters, it may be >5µg/L (even up to 100) indicates eutrophic condition. So >5µg/L can be represented in one colour (red), but smaller values should be graduated to see the difference in wider area. I feel that the second figure is almost perfect for my objective, but only the legend should be like in the first figure. 0-0.2 range represented by blue and violet colors in the 2nd image, it covers a wider area. – Karnan May 17 at 4:49
  • @aldo_tapia, I like to keep the equal color strip, but label values are not equal (like in 1st image). The equal color strip with labels like 0.00 0.21 1.21 2.01 3.01 4.01 15.00 – Karnan May 17 at 5:10
  • I used this way, I have truncated values above 5 as 5///// zz=ifelse(z>5,"5",z)///// then breaks and respective labels///// brks= c(seq( 0, 0.5,,10), c(seq( 0.5001, 1.2,,5)),c(seq( 1.2001, 5,,5)))///// arg=list(at=c(0,1,2,3,4,5), labels=c("0","1","2","3","4",">5"))///// image.plot(x,y,zz, breaks=brks, axis.args = arg)///// Now the legend looks better. – Karnan May 17 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.