Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: MarkerCluster Pie Charts and Bar Charts #173

Closed
ngfrey opened this issue Sep 14, 2019 · 3 comments
Closed

Feature Request: MarkerCluster Pie Charts and Bar Charts #173

ngfrey opened this issue Sep 14, 2019 · 3 comments

Comments

@ngfrey
Copy link

ngfrey commented Sep 14, 2019

It would be wonderful if it was easy to replicate the example from gisminister linked below, but also specify colors to the pie-charts via either a pal function, a vector of colors, or a dataframe of key-value stores.

Leaflet Pie Chart Markers Example:
http://bl.ocks.org/gisminister/10001728

Likewise, it would be wonderful to also have bar charts, as shown in leaflet.minicharts. Example here : https://cran.r-project.org/web/packages/leaflet.minicharts/vignettes/introduction.html

@trafficonese
Copy link
Owner

I just published a new branch at leaflet.extras2 which allows to use piecharts, vertical and horizontal barcharts with d3.

You can install the branch with
remotes::install_github("trafficonese/leaflet.extras2", ref = "clustercharts")

Here is a working Shiny-App with Clustercharts

or you can check out these little examples:

library(sf)
library(leaflet)
library(leaflet.extras2)

data <- sf::st_as_sf(breweries91)
categories <- c("Schwer", "Mäßig", "Leicht", "kein Schaden")
data$category <- sample(categories, size = nrow(data), replace = TRUE)
data$label <- sample(breweries91$brewery, size = nrow(data), replace = TRUE)

## Pie Chart
leaflet() %>%
  addProviderTiles("CartoDB.Positron") %>%
  leaflet::addLayersControl(overlayGroups = "clustermarkers") %>%
  addClusterCharts(data = data
                   , categoryField = "category"
                   , options = clusterchartOptions(rmax = 40, innerRadius = 10, size = 10)
                   , categoryMap = data.frame(labels = categories,
                                              colors  = c("#F88", "#FA0", "#FF3", "#BFB"))
                   , group = "clustermarkers"
                   , popupFields = c("brewery", "address", "zipcode", "category")
                   , label = "label"
                   , legendOptions = list(title = "Some special Title", position = "topright")
  )

## Bar Chart
leaflet() %>%
  addProviderTiles("CartoDB.Positron") %>%
  leaflet::addLayersControl(overlayGroups = "clustermarkers") %>%
  addClusterCharts(data = data
                   , type = "bar"
                   # , type = "horizontal"
                   , categoryField = "category"
                   , categoryMap = data.frame(labels = categories,
                                              strokes = "gray")
                   , group = "clustermarkers"
                   , label = "label"
  )

Todos / Ideas:

  • Icons only work in a shiny-app so far, should icons be imported, base64 encoded?
  • Check if data geometry type is Point?
  • Only support Geojson through sf and yyjsonr?
  • Other Visualizations? Histograms?
  • Other Calculations than d3.max?
  • Order title in order of legend or in frequency?

Tell me what you think, if it needs some adjustments or if there is something missing.. 🐝

@trafficonese
Copy link
Owner

I think #191 is related.

@trafficonese
Copy link
Owner

trafficonese commented Aug 13, 2024

I opened a PR trafficonese/leaflet.extras2#69 and will close the issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants