If you are knitting to an HTML-based format, the only supported options are vega.width, vega.height (as pixels) and vega.embed (as a list). If you are knitting to a non-HTML-based format, you additionally have the options dev, out.width and out.height available.

knit_print.vegaspec(spec, ..., options = NULL)

Arguments

spec

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

...

other arguments

options

list, knitr options

Details

The biggest thing to keep in mind about a Vega visualization is that very often, the chart tells you how much space it needs, rather than than you tell it how much space it has available. In the future, it may reveal itself how to manage better this "conversation".

HTML-based

When knitting to an HTML-based format, the spec is rendered as normal, it calls vegawidget() using the options vega.width, vega.height and vega.embed:

  • vega.width and vega.height are passed to vegawidget() as width and height, respectively. These values are coerced to numeric, so it is ineffective to specify a percentage. They are passed to vw_autosize() to resize the chart, if possible.

  • vega.embed is passed to vegawidget() as embed. The function vega_embed() can be useful to set vega.embed.

Non-HTML-based

When knitting to an non-HTML-based format, e.g. github_document or pdf_document, this function will convert the chart to an image, then knitr will incorporate the image into your document. You have the additional knitr options dev, out.width, and out.height:

  • The supported values of dev are "png", "svg", and "pdf". If you are knitting to a LaTeX format (e.g. pdf_document) and you specify dev as "svg", it will be implemented as "pdf".

  • To scale the image within your document, you can use out.width or out.height. Because the image will already have an aspect ratio, it is recommended to specify no more than one of these.