I have an elevation model plotted in R Code:
library(raster)
data(volcano)
r <- raster(volcano)
plot(r, col = topo.colors(20))
Plot:

how can we retrieve the values of the intervals in the legend, that is, in the example-->100,120,140,160,180
I have an elevation model plotted in R Code:
library(raster)
data(volcano)
r <- raster(volcano)
plot(r, col = topo.colors(20))
Plot:

how can we retrieve the values of the intervals in the legend, that is, in the example-->100,120,140,160,180
The legend is a summary of the raster values. Therefore, you will need to extract the pertinent raster values. This should do it:
library(raster)
data(volcano)
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