add_data: Add data to a Vega-Lite spec

Description Usage Arguments References Examples

View source: R/data.r

Description

Vega-Lite is more lightweight than full Vega. However, the spec is flexible enough to support embedded data or using external sources that are in JSON, CSV or TSV format.

Usage

1
add_data(vl, source, format_type = NULL)

Arguments

vl

a Vega-Lite object

source

you can specify a (fully qualified) URL or an existing data.frame (or ts) object or a reference to a local file. For the URL case, the url component of data will be set. You can help Vega-Lite out by giving it a hint for the data type with format_type but it is not required. For the local data.frame case it will embed the data into the spec. For the case where a local file is specified, it will be read in (either a JSON file, CSV file or TSV file) and converted to a data.frame and embedded.

format_type

if source is a URL, this should be one of json, csv or tsv). It is not required and it is ignored if source is not a URL.

References

Vega-Lite Data spec

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
dat <- jsonlite::fromJSON('[
    {"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
    {"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
    {"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
  ]')

vegalite() %>%
  add_data(dat) %>%
  encode_x("a", "ordinal") %>%
  encode_y("b", "quantitative") %>%
  mark_bar()

Example output



vegalite documentation built on May 2, 2019, 10:46 a.m.