Closed ngfrey closed 4 days ago
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:
sf
and yyjsonr
? Tell me what you think, if it needs some adjustments or if there is something missing.. 🐝
I think https://github.com/trafficonese/leaflet.extras/issues/191 is related.
I opened a PR https://github.com/trafficonese/leaflet.extras2/pull/69 and will close the issue here
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