Closed victorhdc closed 5 years ago
This is currently not possible, but I've wanted to do something about this for a while. I'll have a think about possible solutions and update this issue if I come up with something.
@victorhdc Could you please try the issue152
branch and let me know what you think?
devtools::install_github("SymbolixAU/mapdeck", ref = "issue152")
I've created two new functions
legend_element()
- for creating specific legend elementsmapdeck_legend()
- for formatting the legend_elements
ready for the mapExample
sf <- spatialwidget::widget_melbourne
sf$my_colour <- ifelse( substr(sf$SA2_NAME, 1, 1) == "A", "#00FF00FF", "#FF0000FF")
l1 <- legend_element(
variables = c("begins with A", "Doesn't begin with A")
, colours = c("#00FF00FF", "#FF0000FF")
, colour_type = "fill"
, variable_type = "category"
)
js <- mapdeck_legend(l1)
js
# {"fill_colour":{"colour":["#00FF00FF","#FF0000FF"],"variable":["begins with A","Doesn't begin with A"],"colourType":["fill_colour"],"type":["category"],"title":[""],"css":[""]}}
mapdeck( ) %>%
add_polygon(
data = sf
, fill_colour = "my_colour"
, legend = js
)
Works exactly as needed, thank you very much. I think it was a great idea to separate the logical legend definition from the json object.
reopening so it reminds me to document, test and merge to master
I think it was a great idea to separate the logical legend definition from the json object.
yeah it was needed because there can be a different legends for different colouring options (fill, stroke), so I thought making individual elements first would be easier to handle in code.
Is there a way to specify a character column for legend values, when using manual hex string colours? Using the manual colours example: https://symbolixau.github.io/mapdeck/articles/colours.html#manual-colours
When a legend is included, the legend values are the hex color strings. How can I use a different column for legend values?
TODO