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

Add control on min and max size of symbols #88

Open sylvaine31 opened 2 months ago

sylvaine31 commented 2 months ago

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.

tomroh commented 2 months ago

@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.

sylvaine31 commented 1 month ago

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)