image {vegawidget} | R Documentation |
Create or write image
Description
If you have V8,
withr, and fs
installed, you can use these functions can to create
or write images as PNG or SVG, using a vegaspec
or vegawidget
.
To convert to a bitmap, or write a PNG file, you will additionally need
the rsvg and
png packages.
Usage
vw_to_svg(spec, width = NULL, height = NULL, base_url = NULL, seed = NULL)
vw_to_bitmap(spec, scale = 1, width = NULL, height = NULL, ...)
vw_write_svg(spec, path, width = NULL, height = NULL, ...)
vw_write_png(spec, path, scale = 1, width = NULL, height = NULL, ...)
Arguments
spec |
An object to be coerced to |
width |
|
height |
|
base_url |
|
seed |
|
scale |
|
... |
additional arguments passed to |
path |
|
Details
These functions can be called using (an object that can be coerced to)
a vegaspec
.
The scripts used are adapted from the Vega command line utilities.
Value
vw_to_svg()
character
, SVG stringvw_to_bitmap()
array
, bitmap arrayvw_write_svg()
invisible
vegaspec
orvegawidget
, called for side-effectsvw_write_png()
invisible
vegaspec
orvegawidget
, called for side-effects
See Also
Examples
# call any of these functions using either a vegaspec or a vegawidget
svg <- vw_to_svg(vegawidget(spec_mtcars))
bmp <- vw_to_bitmap(spec_mtcars)
vw_write_png(spec_mtcars, file.path(tempdir(), "temp.png"))
vw_write_svg(spec_mtcars, file.path(tempdir(), "temp.svg"))
# To specify the path to a local file, use base_url
spec_precip <-
list(
`$schema` = vega_schema(),
data = list(url = "seattle-weather.csv"),
mark = "tick",
encoding = list(
x = list(field = "precipitation", type = "quantitative")
)
) %>%
as_vegaspec()
data_dir <- system.file("example-data/", package = "vegawidget")
vw_write_png(
spec_precip,
file.path(tempdir(), "temp-local.png"),
base_url = data_dir
)