| Title: | Insert plots and SVG as inline content into Quarto and R Markdown |
|---|---|
| Description: | Render plots as SVG content and insert this or other SVG content into Quarto and R Markdown output as inline content. |
| Authors: | Matt Kerlogue [aut, cre] |
| Maintainer: | Matt Kerlogue <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-05-21 05:52:20 UTC |
| Source: | https://github.com/mattkerlogue/inlinesvg |
Inserts the content of the SVG file as inline SVG content, i.e. into the body of the resulting HTML.
inline_svg_file( path, id = NULL, role = NULL, alt_title = NULL, alt_description = NULL, source_note = NULL, strip_ns = TRUE, dimensions = c("preserve", "strip", "replace"), width = NULL, height = NULL, units = NULL )inline_svg_file( path, id = NULL, role = NULL, alt_title = NULL, alt_description = NULL, source_note = NULL, strip_ns = TRUE, dimensions = c("preserve", "strip", "replace"), width = NULL, height = NULL, units = NULL )
path |
Path to the SVG file |
id |
An id value for the SVG element within the HTML document (optional) |
role |
The ARIA role for the SVG element (optional) |
alt_title |
A short title for assistive technology users (optional) |
alt_description |
A longer description for assistive technology users (optional) |
source_note |
Text to include in a containing |
strip_ns |
Whether to remove the XML DTD |
dimensions |
Whether to 'preserve' dimensions defined in the SVG tag, to 'strip' them or 'replace' them with provided values |
width |
The width of the SVG element (optional) |
height |
The height of the SVG element (optional) |
units |
The units for width and height (optional) |
In Quarto and R Markdown documents inserting SVG images via standard image
markdown (e.g. ) or HTML <img> tags results in an
SVG that is rendered as an image and cannot be interacted with by the
user (e.g. selecting text), nor can elements be modified by CSS.
inline_svg_file() takes the content of an SVG file and inserts it as
inline SVG content within the body of the rendered HTML document.
Optionally an element id can be specified (if not provided one will be
created), if provided will overwrite any existing 'id' attribute encoded in
the SVG object.
A source_note can be provided that will be included after the image, it
has the class "svg-source-note" for styling with CSS and an id starting
with "svg-source-note-" and then using the supplied or generated id.
svglite::svglite() encodes the width and height (in points) of the object
into the <svg> tag (in addition to the viewBox declaration), this can
cause issues for responsive scaling of plots. The dimensions argument can
"preserve" any existing dimensions (the default), "strip" the dimensions
removing them from the tag, or "replace" them with new dimensions supplied
using the width, height and units arguments.
An htmltools::HTML() object
A wrapper to svglite::svglite() for saving plots as SVG files and
inserting as inline_content.
svg_plot( plot, path = NULL, width, height, units = c("px", "pt", "cm", "mm", "in"), overwrite = TRUE, standalone = TRUE, ... ) inline_svg_plot( plot, path = NULL, width, height, units = c("px", "pt", "cm", "mm", "in"), overwrite = NULL, alt_title = NULL, alt_description = NULL, source_note = NULL, id = NULL, explicit_size = FALSE, standalone = FALSE, ... )svg_plot( plot, path = NULL, width, height, units = c("px", "pt", "cm", "mm", "in"), overwrite = TRUE, standalone = TRUE, ... ) inline_svg_plot( plot, path = NULL, width, height, units = c("px", "pt", "cm", "mm", "in"), overwrite = NULL, alt_title = NULL, alt_description = NULL, source_note = NULL, id = NULL, explicit_size = FALSE, standalone = FALSE, ... )
plot |
A graphics object to plot. |
path |
A file path to save the SVG plot to (optional). |
width |
Width of the output plot. |
height |
Height of the output plot. |
units |
Units used for width and height. |
overwrite |
Should files be overwritten (default is |
standalone |
Whether |
... |
Arguments passed on to |
alt_title |
Short alt text to include in the inline SVG (optional). |
alt_description |
Long-form alt text to include in the inline SVG (optional). |
source_note |
Text to include in a containing |
id |
An id for referencing the SVG within the HTML/CSS (optional) |
explicit_size |
Whether the inline |
svg_plot() is a wrapper around the svglite::svglite() graphics
device that simplifies its use for saving plots. Compared to
svglite::svglite() users do not need to manually active and deactivate
the graphics device, users can also specify width and height in dimensions
other than inches.
inline_svg_plot() combines svg_plot() with inline_svg_file() to insert
the plot as inline SVG content within a Quarto or R Markdown document.
Unless otherwise specified the chart is rendered to SVG via a temporary
file, this path is returned invisibly from svg_plot(). If re-using plots
elsewhere it is advised to use an explicit path name and use
inline_svg_file() to re-insert the SVG content rather than rely on the
temporary path provided by svg_plot().
An id for the inline SVG can be provided for so that it is directly
accessible via HTML or CSS (e.g. for linking or styling).
A source_note can be used to insert text immediately after the SVG image
The alt_title and alt_description allow for the insertion of alt text
into the SVG content, alt_title is intended for short descriptions and
alt_description for longer-form descriptions. If the supplied plot is a
a ggplot2::ggplot() object and no alt text is supplied then the plot
object will be inspected for alt text, if the alt text is 150 characters or
less it will be used for alt_title but if longer it will be used for
alt_description.