png_to_grob: Create image grob from png and output the width and height

View source: R/ggplot_utils.R

png_to_grobR Documentation

Create image grob from png and output the width and height

Description

This takes a png file and converts it to a grob. This is useful in combination with ggplot2::annotation_custom()

Usage

png_to_grob(source)

Arguments

source

name of image to read

Examples


library(ggplot2)

img <- png_to_grob(system.file("img", "Rlogo.png", package = "png"))

ggplot(mtcars, aes(x = mpg, y = wt, color = factor(cyl))) +
  geom_point() +
  annotation_custom(img, xmin = 25, xmax = 30, ymin = 4, ymax = 5)

kylebutts/kfbmisc documentation built on April 17, 2025, 5:20 p.m.