This is the key difference with the vegalite package: it provides a set of higher-level functions to compose specifications, whereas vegawidget concerns itself mainly with the rendering of the htmlwidget.
To be clear, although Vega-Lite offers a grammar-of-graphics, this package does not offer a user-friendly framework to compose graphics, like those provided by ggplot2 or ggvis. However, this package may be useful to:
vegawidget offers Vega-Lite 3.3.0 and Vega 5.4.0. Consequently, this package works only with browsers that support ES6. This includes all modern browsers and the 1.2 version of the RStudio IDE.
When knitting to a non-HTML format, e.g.
github_document, this package provides a
knit_print() function that will intercept the normal renderer, using instead its own renderer, allowing you to specify
"pdf". It requires that nodejs be installed on your system, as well as the R packages rsvg and png. MacOS users will require an X11 system, such as XQuartz, to be installed.
You can install vegawidget from CRAN with:
The development version of vegawidget is available from GitHub with:
Vega(-Lite) specifications are just text, formatted as JSON. However, in R, we can use lists to build specifications:
library("vegawidget") spec_mtcars <- list( `$schema` = vega_schema(), # specifies Vega-Lite description = "An mtcars example.", data = list(values = mtcars), mark = "point", encoding = list( x = list(field = "wt", type = "quantitative"), y = list(field = "mpg", type = "quantitative"), color = list(field = "cyl", type = "nominal") ) ) %>% as_vegaspec()
as_vegaspec() function is used to turn the list into a vegaspec; many of this package’s functions are built to support, and render, vegaspecs:
The rendering of the chart above depends on where you are reading it:
On this package’s pkgdown site, it is rendered as part of an HTML environment, showing its full capabilities.
At its GitHub code site, the chart is further rendered to a static SVG file, then incorporated into the Markdown rendering.
For more, please see our Getting Started article. For other introductory material, please see:
Other articles for this package: