Here is an incredibly clunky way by inserting the raster at the gtable
level and then re-inserting the gtable as a custom annotation. I'm sorry I couldn't find a more succinct way.
library(ggplot2)
library(magick)
#> Linking to ImageMagick 6.9.11.57
#> Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
#> Disabled features: fontconfig, x11
data(mpg, package="ggplot2")
# Load a logo from Github
logo <- image_read("https://jeroen.github.io/images/frink.png")
# Plot Code
g <- ggplot(mpg, aes(cty, hwy)) +
geom_count(col="tomato3", show.legend=F)
# Convert to gtable
g <- ggplotGrob(g)
# Save logo as grob
grob <- grid::rasterGrob(logo, x = 0.04, y = 0.03, just = c('left', 'bottom'),
width = unit(1, 'inches'))
# Insert grob in gtable
g <- gtable::gtable_add_grob(
g, grob, t = 1, l = 1, b = dim(g)[1], r = dim(g)[2]
)
# Add old plot as annotation to new plot with void theme
ggplot() +
annotation_custom(g) +
theme_void()
ggsave('Plot.tiff',width =10,height = 6, device = 'tiff', dpi = 700)
Created on 2021-01-21 by the reprex package (v0.3.0)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…