dw_legend_to_string: Creates a legend from a Datawrapper chart

View source: R/dw_legend_to_string.R

dw_legend_to_stringR Documentation

Creates a legend from a Datawrapper chart

Description

\lifecycle

deprecated 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.

Usage

dw_legend_to_string(
  legend,
  return_val = c("string", "vector", "html"),
  use_ranges = FALSE
)

Arguments

legend

Required. A vector containing the legend (e.g. retrieved from a call with dw_retrieve_chart_metadata(chart_id)).

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. ⁠(0,10]⁠). Defaults to FALSE.

Value

A string, vector or HTML (as string), as defined in return_val.

How to

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"]].

Author(s)

Benedict Witzenberger

Examples


## Not run: 

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

## End(Not run)

munichrocker/DatawRappr documentation built on March 20, 2024, 6:08 a.m.