tomroh / leaflegend

Provides extensions to the leaflet R package to customize legends with images, text styling, orientation, sizing, and symbology.
https://leaflegend.delveds.com
Other
34 stars 3 forks source link

New feature to have Stacked or nested bubbles sizeson legend when plotting bubbles in tmap #76

Closed tomroh closed 11 months ago

tomroh commented 11 months ago

See https://github.com/r-tmap/tmap/issues/777.

tomroh commented 11 months ago

034cdbbe5adae872bb4756030494acea7d12c8fb

addSizeLegend gains an argument stacked that will produce stacked size charts. This works for all available shapes but only circle, rect, and triangle are recommended.

library(leaflet)
library(leaflegend)
data("quakes")
baseSize <- 5
numPal <- colorNumeric('viridis', 10^(quakes$mag))
leaflet(quakes) |>
  addTiles() |>
  addLegendSize(
    values = ~10^(mag),
    title = 'Magnitude',
    baseSize = baseSize,
    shape = 'circle',
    color = 'black',
    fillColor = 'red',
    position = 'topright',
    stacked = TRUE,
    breaks = 5,
    strokeWidth = 2) |>
  addLegendSize(
    values = ~10^(mag),
    title = 'Magnitude',
    baseSize = baseSize,
    shape = 'triangle',
    color = 'black',
    fillColor = 'red',
    position = 'topright',
    stacked = TRUE,
    breaks = 5,
    strokeWidth = 2) |>
  addLegendSize(
    values = ~10^(mag),
    title = 'Magnitude',
    baseSize = baseSize,
    shape = 'diamond',
    color = 'black',
    fillColor = 'red',
    position = 'topright',
    stacked = TRUE,
    breaks = 5,
    strokeWidth = 2) |>
  addLegendSize(
    values = ~10^(mag),
    title = 'Magnitude',
    baseSize = baseSize,
    shape = 'stadium',
    color = 'black',
    fillColor = 'red',
    position = 'topright',
    stacked = TRUE,
    breaks = 5,
    strokeWidth = 2)
image