knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  dev = "svg"
)

vegadown

CRAN status Lifecycle: experimental R-CMD-check

The goal of vegadown is to help you compose Vega and Vega-Lite specs within RMarkdown documents.

The audience for this package are people who are already comfortable with Vega-Lite JSON specs. Compared with using the vegawiget package alone, vegadown offers a quicker, more minimal, environment for developing specs. However, it still does not provide humane feedback when something goes wrong.

Installation

This package is not (yet) on CRAN. You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("vegawidget/vegadown")

Example

library("vegadown")
library("palmerpenguins")

Using vegawidget alone, it can be a bit awkward to compose specs using lists.

Using this package, you can compose using JSON or YAML within RMarkdown chunks by specifying the chunk's language as vegajson or vegayaml (vegayml). You can interpolate objects from your R environment by using the delimiters ${}, much like you would using the glue package.

Here's what your code chunk would look like:

```{vegajson json-cars}`r ''`
{
  "$schema": "${vega_schema()}",
  "data": {"values": "${penguins}"},
  "mark": "point",
  "encoding": {
    "x": {
      "field": "bill_length_mm",
      "type": "quantitative",
      "scale": {"zero": false}
    },
    "y": {
      "field": "bill_depth_mm",
      "type": "quantitative",
      "scale": {"zero": false}
    },
    "color": {"field": "species", "type": "nominal"}
  }
}
```

Here's how it would appear:

```{vegajson json-penguins, echo=FALSE} { "$schema": "${vega_schema()}", "data": {"values": "${penguins}"}, "mark": "point", "encoding": { "x": { "field": "bill_length_mm", "type": "quantitative", "scale": {"zero": false} }, "y": { "field": "bill_depth_mm", "type": "quantitative", "scale": {"zero": false} }, "color": {"field": "species", "type": "nominal"} } }

You can access your vegaspecs elsewhere in your RMarkdown document, using the `vegadown()` function with the chunk label:

```r
str(vegadown("json-penguins"))

For more details, please see the getting started article, which also shows:

Code of Conduct

Please note that the vegadown project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



vegawidget/vegadown documentation built on Jan. 23, 2021, 10:34 a.m.