canvas: Add a canvas specification to a ggplot object

View source: R/element.R

canvasR Documentation

Add a canvas specification to a ggplot object

Description

A canvas specification essentially comprises a set of parameters from ggplot2::ggsave(). When a plot with this canvas specification is printed, it is rendered as it would appear if saved to a file with the specified dimensions.

Usage

canvas(
  width,
  height,
  units = c("in", "cm", "mm", "px"),
  dpi = 300,
  scale = 1,
  bg = "white"
)

Arguments

width, height

Plot size in units expressed by the units argument. If not supplied, uses the size of the current graphics device.

units

One of the following units in which the width and height arguments are expressed: "in", "cm", "mm" or "px".

dpi

Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.

scale

Multiplicative scaling factor.

bg

Background colour. If NULL, uses the plot.background fill value from the plot theme.

Value

An object of class canvas that can be added to a ggplot object to specify the plot dimensions.

Examples


library(ggplot2)
p <-
  ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  ggtitle("My awesome plot")

p + canvas(3, 3)
p + canvas(5, 3, dpi = 400)


ggview documentation built on Oct. 2, 2024, 5:06 p.m.