png_retina: Create png for retina display

View source: R/plot_devices.R

png_retinaR Documentation

Create png for retina display

Description

'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()]

Usage

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
)

Arguments

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 PATH_MAX characters long, and may be truncated if not. See postscript for further details.) Tilde expansion is performed where supported by the platform. An input with a marked encoding is converted to the native encoding on an error is given.

width

the width of the device.

height

the height of the device.

units

The units in which height and width are given. Can be px (pixels, the default), in (inches), cm or mm.

pointsize

the default pointsize of plotted text, interpreted as big points (1/72 inch) at res ppi.

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 units other than the default, and to convert points to pixels.

...

for type = "Xlib" only, additional arguments to the underlying X11 device such as fonts or family.

For types "cairo" and "quartz", the family argument can be supplied. See the ‘Cairo fonts’ section in the help for X11.

For type "cairo", the symbolfamily argument can be supplied. See X11.options.

type

character string, one of "Xlib" or "quartz" (some macOS builds) or "cairo". The latter will only be available if the system was compiled with support for cairo – otherwise "Xlib" will be used. The default is set by getOption("bitmapType") – the ‘out of the box’ default is "quartz" or "cairo" where available, otherwise "Xlib".

antialias

for type = "cairo", giving the type of anti-aliasing (if any) to be used for fonts and lines (but not fills). See X11. The default is set by X11.options. Also for type = "quartz", where antialiasing is used unless antialias = "none".

x

a ggplot2 object

Value

A plot device is opened: nothing is returned to the R interpreter

Functions

  • save_png_retina:

See Also

png

Examples


# 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)
}

bcgov/envreportutils documentation built on Feb. 1, 2024, 8:48 p.m.