magick (version 2.0)

image_ggplot: Image to ggplot

Description

Converts image to raster using image_raster() and then plots it with ggplot2 geom_raster. See examples for other ways to use magick images in ggplot2.

Usage

image_ggplot(image)

Arguments

image

magick image object returned by image_read() or image_graph()

Examples

Run this code
# NOT RUN {
# Plot with base R
plot(logo)

# Plot image with ggplot2
library(ggplot2)
myplot <- image_ggplot(logo)
myplot + ggtitle("Test plot")

# Or add to plot as annotation
image <- image_fill(logo, 'none')
raster <- as.raster(image)
myplot <- qplot(mpg, wt, data = mtcars)
myplot + annotation_raster(raster, 25, 35, 3, 5)

# Or overplot image using grid
library(grid)
qplot(speed, dist, data = cars, geom = c("point", "smooth"))
grid.raster(image)
# }

Run the code above in your browser using DataCamp Workspace