0

I have a polyline that I am displaying in the R leaflet with the following code:

leaf <- leaflet() %>% addTiles() %>% 
        addPolylines(data= data, weight = data$vol)

As you can see, I am defining the weight of each line based on the value of the vol field in the database and so I get a map like this:

enter image description here

I know that I can add a color legend to this by adding the col property to the polyline and using addLegend like this:

pal <- colorNumeric("YlOrRd", domain=data$vol)

leaf <- leaflet() %>% addTiles() %>%
        addPolylines(data=data, weight=data$vol, col=~pal(data$vol)) %>%
        addLegend(position="topright", pal=pal, values=data$vol)

And I will get the desired output with the color legend similar to this screenshot: enter image description here

However, what I want to do is to have a legend for the thickness of the lines in the first map, instead of a legend for the color of the lines in the second map. So, imagine a legend like this:

enter image description here

I know the addLegend function adds color legends, but I was wondering if there is a way for me to add a legend for the line weight (or width/thickness) to the map?

AkbarB
  • 460
  • 7
  • 24

0 Answers0