Capture a plot as a self-contained <img> tag
Capture a plot as a self-contained <img> tag
plotTag(
expr,
alt,
device = defaultPngDevice(),
width = 400,
height = 400,
pixelratio = 2,
mimeType = "image/png",
deviceArgs = list(),
attribs = list(),
suppressSize = c("none", "x", "y", "xy")
)expr |
A plotting expression that generates a plot (or yields an object that generates a plot when printed, like a ggplot2). |
alt |
A single-element character vector that contains a text description of the image. This is used by accessibility tools, such as screen readers for vision impaired users. |
device |
A graphics device function; by default, this will be either
|
width, height |
The width/height that the generated tag should be displayed at, in logical (browser) pixels. |
pixelratio |
Indicates the ratio between physical and logical units of
length. For PNGs that may be displayed on high-DPI screens, use |
mimeType |
The MIME type associated with the |
deviceArgs |
A list of additional arguments that should be included when
the |
attribs |
A list of additional attributes that should be included on the
generated |
suppressSize |
By default, |
A browsable() HTML <img> tag object. Print it at
the console to preview, or call as.character() on it to view the HTML
source.
capturePlot() saves plots as an image file.
img <- plotTag({
plot(cars)
}, "A plot of the 'cars' dataset", width = 375, height = 275)
if (interactive()) img
svg <- plotTag(plot(pressure), "A plot of the 'pressure' dataset",
device = grDevices::svg, width = 375, height = 275, pixelratio = 1/72,
mimeType = "image/svg+xml")
if (interactive()) svgPlease choose more modern alternatives, such as Google Chrome or Mozilla Firefox.