leaflegend icon indicating copy to clipboard operation
leaflegend copied to clipboard

Add control on min and max size of symbols

Open sylvaine31 opened this issue 1 year ago • 2 comments

Hello, I don't know if it's possible (or easy), but it would be nice to have more control over the legend size. For example, instead of just the "baseSize" argument, having "minSize" and "maxSize" arguments would be great.

sylvaine31 avatar May 28 '24 09:05 sylvaine31

@sylvaine31, this is a significant departure from the way it is currently setup. How does the current implementation not meet your expectations? You do have control over setting min and max size just not directly. You could pass a vector of min/max instead of directly using your data and adjust baseSize and breaks to get an approximation of your desired min/max.

tomroh avatar May 30 '24 23:05 tomroh

Hello, Thanks for your quick answer. I think I misused the package. In the example below, I can't achieve to see the 3 points with a decent size for the bigger one :

ploup <- tibble::tribble(
  ~value, ~lat, ~long, 
  1,1.2, 43,
  50,1.3, 42.5,
  143,1.25, 43.5) %>% 
  sf::st_as_sf(coords = c("lat", "long")) %>% 
  sf::st_set_crs(4326)

# création des tailles de symboles

basesize = 20
symbols <- leaflegend::makeSymbolsSize(
  values = ploup$value,
  shape = 'circle',
  color = 'red',
  fillColor = 'red',
  opacity = .5,
  baseSize =basesize
)

# Carte
 library(leaflet)
  leaflet() %>% 
  addProviderTiles("CartoDB.Positron", group = "CartoDB.Positron") %>%
  addMarkers(data = ploup,
             icon = symbols)%>%
  leaflegend::addLegendSize(
    values = ploup$value,
    position = "topright",
    color = 'red',
    fillColor = 'red',
    opacity = .5,
    baseSize = basesize,
    shape = 'circle',
    orientation = 'vertical',
    breaks = 5,
    stacked = FALSE)

sylvaine31 avatar Jun 05 '24 07:06 sylvaine31