Skip to contents

This function saves a ggplot2 plot as a magick image object, using the desired width and height in inches and dpi resolution.

Usage

ggplot_to_image(
  plot_object,
  image_width = 10,
  image_height = 10,
  image_resolution = 300
)

Arguments

plot_object

ggplot2 plot that needs to be saved as image.

image_width

Width of the image in inches. Default is 10.

image_height

Height of the image in inches. Default is 10.

image_resolution

Resolution of the image in dpi. Default is 300.

Value

A magick image object of the ggplot2 plot.

Examples

if (FALSE) {
library(ggplot2)
p <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point()
img <- ggsave_to_image(p)
}