A helper function that creates a legend as string, vector or HTML from an existing legend in a Datawrapper chart. Will be deprecated soon, as it's no longer needed. Datawrapper now offers a better option via its interface.
dw_legend_to_string( legend, return_val = c("string", "vector", "html"), use_ranges = FALSE )
legend | Required. A vector containing the legend (e.g. retrieved from a call with |
---|---|
return_val | Required. One of c("string", "vector", "html"). Set the output type. Defaults to "string". |
use_ranges | Optional. Filters out automatically generated ranges (e.g. |
A string, vector or HTML (as string), as defined in return_val
.
Create a chart that displays the required legend. Then use dw_retrieve_chart_metadata(chart_id)
to download the meta-information of your chart into a R-variable.
You may then extract the legend as a string. It might for example be stored in metadata[["content"]][["metadata"]][["visualize"]][["categories"]]
or in metadata[["content"]][["metadata"]][["visualize"]][["custom-colors"]]
.
Benedict Witzenberger
if (FALSE) { dw_legend_to_string(legend) dw_legend_to_string(legend, return_val = "html") # return simple HTML-code dw_legend_to_string(legend, use_ranges = TRUE) # filter out ranges }