Uses the export endpoint to export a chart as PNG, PDF, or SVG (the latter two require paid plans).

dw_export_chart(
  chart_id,
  type = c("png", "pdf", "svg"),
  unit = c("px", "inch", "mm"),
  mode = c("rgb", "cmyk"),
  width = NULL,
  height = NULL,
  plain = TRUE,
  scale = 2,
  border_width = 0,
  border_color = NULL,
  transparent = FALSE,
  api_key = "environment"
)

Arguments

chart_id

Required. A Datawrapper-chart-id as character string, usually a five character combination of digits and letters, e.g. "aBcDe". Or a dw_chart-object.

type

Required. One of png, pdf, or svg. Defaults to png.

unit

Define units which border_width, height and width are measured in. png only works with px; pdf works with any of them; svg should have this set to NULL.

mode

color movde for output. Defaults to rgb. Only applicable to pdf output type.

width, height

width and height of the visualization; if not specified it takes the chart width/height.

plain

if TRUE (the default) only the visualization will be exported; FALSE includes header and footer.

scale

defines multiplier for the size; e.g. if 3 then the chart will be 3x wider and taller; Defaults to 2.

border_width

margin around the visualization; e.g. if border_width is 20 and unit is px, the visualization will have a 20px margin. Default is 0.

border_color

color of the border; The default is the same as the visualization (likely white).

transparent

make the background transparent; The default is FALSE; will override border_color.

api_key

Optional. A Datawrapper-API-key as character string. Defaults to "environment" - tries to automatically retrieve the key that's stored in the .Reviron-file by datawrapper_auth.

Value

for png, a {magick} object; for pdf, invisible raw vector with PDF content; for svg, invisible character vector with SVG content

Note

PDF and SVG export require paid plans

Examples

if (FALSE) dw_export_chart("aBcDE") # uses the preset key in the .Renviron-file