Skip to contents

Render a ggplot/grob/gtable to a magick image

Usage

as_magick(x, width = 6, height = 4, dpi = 300, bg = "white")

Arguments

x

ggplot, grob, or gtable.

width, height

Plot size in inches.

dpi

Resolution for rasterization.

bg

Background color.

Value

A magick-image.

Examples

if (requireNamespace("ggplot2", quietly = TRUE)) {
  p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) +
    ggplot2::geom_point()
  as_magick(p)
}
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 PNG     1800   1200 sRGB       FALSE    44055 118x118