The goal of vegabrite is to provide an R api for building up vega-lite
specs. For a guide on getting started using vegabrite
, check out the
getting started
vignette.
The example
gallery
show-cases some of the many different types of plots that can be made
using vegabrite
.
This package is still experimental but has a mostly complete interface for building out Vega-Lite specs and charts. There is still lots of room for improvement in terms of better error handling and warnings when making invalid specs.
For some background and context on the package (previously named vegabrite) you can check out slides from a rstudio::conf talk in January 2020. See also the design vignette for an overview of the design of the package.
Much of the public API is auto-generated via the build.R
script in the
build
directory. The script makes uses of another package,
vlmetabuildr
located within the build
directory.
The API for this package is heavily inspired by the vegalite R package, but is rebuilt from scratch to (1) build up the API semi-automatically based on the Vega-lite schema (an approach inspired by Altair and vega-lite-api) and (2) take advantage of the htmlwidget infrastucture for vega specs provided by the vegawidget package.
vegabrite
is not yet on cran but can be installed from github:
remotes::install_github('vegawidget/vegabrite')
These are some examples showing current capabilities; see examples vignette for more examples, including interactive ones.
library(vegabrite)
vl_chart() %>%
vl_add_data(values = mtcars) %>%
vl_mark_point() %>%
vl_encode_x("wt") %>%
vl_encode_y("mpg")
vl_chart() %>%
vl_add_data(url = "https://vega.github.io/vega-editor/app/data/population.json") %>%
vl_calculate(calculate = "datum.sex == 2 ? 'Female' : 'Male'",
as = "gender") %>%
vl_filter("datum.year == 2000") %>%
vl_encode(x = "age:O", y = "people:Q", color = "gender:N") %>%
vl_stack_y("normalize") %>%
vl_aggregate_y("sum") %>%
vl_axis_y(title = "population") %>%
vl_mark_bar()