I have a simple RasterLayer
in R. I added a column to the attribute table and would like to use these values in the legend of my leaflet
-map.
The RasterLayer
looks like this:
> layer1
class : RasterLayer
dimensions : 38, 40, 1520 (nrow, ncol, ncell)
resolution : 1000, 1000 (x, y)
extent : 4303000, 4343000, 3365000, 3403000 (xmin, xmax, ymin, ymax)
crs : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
source : memory
names : ue65
values : 1, 5 (min, max)
attributes :
ID VALUE percentage
1 1 0
2 2 0-15
3 3 15-20
4 4 20-25
5 5 >25
And the code for making the leaflet map like this:
leaflet() %>%
addProviderTiles('Esri.WorldImagery',group='Imagery') %>%
addProviderTiles('Esri.WorldStreetMap', group='Streets') %>%
addRasterImage(layer1, colors = pal, opacity = 0.7, group = "layer1") %>%
addLayersControl(
baseGroups = c("Imagery", "Streets"),
overlayGroups = c("layer1"),
options = layersControlOptions(collapsed = FALSE)
) %>%
addLegend(pal = pal, values = values(layer1$percentage))
I just cant figure out how to use the percentage
-column from the attributes table in my legend. If I use:
values = values(layer1)
it shows 1-5 in the legend. Any hint would be superhelpfull!!