png_retina | R Documentation |
'png_retina' is a drop-in replacement for the png
function
for creating images for the web for retina devices. Internally, it simply
doubles the width, height, and resolution specified. The intention is then
that in the webpage that you would specify the width
and height
attributes in the html at the original resolution.
'save_png_retina' is a wrapper function around 'png_retina' analagous to [ggplot2::gsave()]
png_retina(
filename = "Rplot%03d.png",
width = 480,
height = 480,
units = "px",
pointsize = 12,
bg = "white",
res = NA,
...,
type = c("cairo", "cairo-png", "Xlib", "quartz"),
antialias
)
save_png_retina(
x,
filename = "Rplot%03d.png",
width = 480,
height = 480,
units = "px",
pointsize = 12,
bg = "white",
res = NA,
...,
type = c("cairo", "cairo-png", "Xlib", "quartz"),
antialias
)
filename |
the output file path.
The page number is substituted if a C integer format is included in
the character string, as in the default. (The result must be less
than |
width |
the width of the device. |
height |
the height of the device. |
units |
The units in which |
pointsize |
the default pointsize of plotted text, interpreted as
big points (1/72 inch) at |
bg |
the initial background colour: can be overridden by setting par("bg"). |
res |
The nominal resolution in ppi which will be recorded in the
bitmap file, if a positive integer. Also used for |
... |
for For types For type |
type |
character string, one of |
antialias |
for |
x |
a ggplot2 object |
A plot device is opened: nothing is returned to the R interpreter
save_png_retina
:
png
# You want to display at 500 * 500 in the web:
png_retina("myplot.svg", width = 500, height = 500)
plot(x = 1:500, y = rnorm(500))
dev.off()
# Although the output image will be 1000 * 1000, in the html you would put:
# <img src="myplot.png", width="500", height="500" />
if (suppressPackageStartupMessages(require("ggplot2", quietly = TRUE))) {
p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point()
file <- tempfile(fileext = ".png")
save_png_retina(p, file)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.