trafficonese / leaflet.extras2

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras2/
GNU General Public License v3.0
85 stars 20 forks source link

"addHexbin" in leaflet.extras2 doesn't allow for mean/sum #49

Open vkentner opened 2 years ago

vkentner commented 2 years ago

Using "addHexbin" in leaflet.extras2 only counts the number of records in each hexbin but there are many use cases for the mean, sum or other calculations within the hexbin. For example a dataset that is a list of species and the abundance of each species. Instead of a count of the number of times a species appears in each hexbin it would be useful to have the total or average abundance in a hexbin. In the example below there is no way to account for or access the abun column when using addHexbin.

library(leaflet)
  library(leaflet.extras2)

  n <- 100000
  df <- data.frame(lat = rnorm(n, 42.0285, .01),
                   lng = rnorm(n, -93.65, .01),
                   abun = rnorm(n, 20000, 1000))

  leaflet(df)  %>%
    addTiles() %>%
    addHexbin(lng = ~lng, lat = ~lat,
              options = hexbinOptions(
                colorRange = c( "purple","blue","green", "yellow"),
                radiusRange = c(1, 20)
              )) 
trafficonese commented 1 year ago

I will look into it. Sounds very reasonable!

trafficonese commented 1 year ago

This would have to be handled in the upstream plugin library. Unfortunately, there's not much i can do on the R-side.

trafficonese commented 3 months ago

I am working on clusterCharts https://github.com/trafficonese/leaflet.extras2/pull/69 that make it possible to cluster and aggregate values from point markers using d3 functions, like sum/min/max/mean/median.

I thought that could be interesting for you @vkentner.

After installing the PR you can check out this Shiny-App:

runApp(system.file("examples/clustercharts_sum.R", package = "leaflet.extras2"))