as_vegaspec: Coerce to vegaspec

Description Usage Arguments Details Value See Also Examples

View source: R/vegaspec.R

Description

Vega and Vega-Lite use JSON as their specification-format. Within R, it seems natural to work with these specifications as lists. Accordingly, a vegaspec is also a list. This family of functions is used to coerce lists, JSON, and character strings to vegaspec.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
as_vegaspec(spec, ...)

## Default S3 method:
as_vegaspec(spec, ...)

## S3 method for class 'vegaspec'
as_vegaspec(spec, ...)

## S3 method for class 'list'
as_vegaspec(spec, ...)

## S3 method for class 'json'
as_vegaspec(spec, ...)

## S3 method for class 'character'
as_vegaspec(spec, ...)

## S3 method for class 'vegawidget'
as_vegaspec(spec, ...)

Arguments

spec

An object to be coerced to vegaspec, a Vega/Vega-Lite specification

...

Other arguments (attempt to future-proof)

Details

The character method for this function will take:

For Vega and Vega-Lite, the translation between lists and JSON is a little bit particular. This function, as_vegaspec(), can be used to translate from JSON; vw_as_json() can be used to translate to JSON.

You can use the function vw_spec_version() to determine if a vegaspec is built for Vega-Lite or Vega. You can use vw_to_vega() to translate a Vega-Lite spec to Vega.

Value

An object with S3 class vegaspec

See Also

Vega, Vega-Lite, vw_as_json(), vw_spec_version(), vw_to_vega()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
  spec <- list(
    `$schema` = vega_schema(),
    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(spec)

  ## Not run: 
    # requires network-access
    as_vegaspec("https://vega.github.io/vega-lite/examples/specs/bar.vl.json")
  
## End(Not run)

vegawidget documentation built on Jan. 23, 2020, 1:06 a.m.