| knit_print.vegaspec {vegawidget} | R Documentation |
Knit-print method
Description
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.
Usage
knit_print.vegaspec(spec, ..., options = NULL)
Arguments
spec |
An object to be coerced to |
... |
other arguments |
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.widthandvega.heightare passed tovegawidget()aswidthandheight, respectively. These values are coerced to numeric, so it is ineffective to specify a percentage. They are passed tovw_autosize()to resize the chart, if possible. -
vega.embedis passed tovegawidget()asembed. The functionvega_embed()can be useful to setvega.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
devare"png","svg", and"pdf". If you are knitting to a LaTeX format (e.g.pdf_document) and you specifydevas"svg", it will be implemented as"pdf".To scale the image within your document, you can use
out.widthorout.height. Because the image will already have an aspect ratio, it is recommended to specify no more than one of these.