I have an elevation model plotted in R Code:

r <- raster(volcano)
plot(r, col = topo.colors(20))

Plot: enter image description here

how can we retrieve the values ​​of the intervals in the legend, that is, in the example-->100,120,140,160,180

  • 1
    Out of curiosity, what do you hope to do with the intervals? +1 for a reproducible example. – Aaron Oct 21 '14 at 12:53
  • I want to made ​​for my application ploter the upper variable, above 180 and below 100 that's just an example I want to get an idea across. – zina_GIS Oct 21 '14 at 13:12
  • 2
    Are you interested in defining the intervals yourself, or do you need to stay with the default intervals? Is this what you are looking to do?: gis.stackexchange.com/a/17352/8104 – Aaron Oct 21 '14 at 14:00
  • I am looking to define them! how I can get the values ​​of the interval? in the example we have given color for each known interval through the pads. but I want to automatically extract values​​. I do not know if I'm clear or I give more precision? – zina_GIS Oct 21 '14 at 14:10
  • 1
    oupss ,"I meant in my last comment, I'm not looking to define them" I want to extract them,sorry! – zina_GIS Oct 21 '14 at 15:06

The legend is a summary of the raster values. Therefore, you will need to extract the pertinent raster values. This should do it:

r = raster(volcano)

min = minValue(r)
max = maxValue(r)
l = c(min:max)
result = l[l %% 20 == 0]

> result
[1] 100 120 140 160 180
| improve this answer | |
  • 1
    Hello @Aaron That was what I needed!! Thank's a lot for your help :) – zina_GIS Oct 21 '14 at 20:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.