I want to add an image or SVG to the ggplot header.

This is what I am aiming for:

get an eye " here "
Below is my best attempt.
I am not happy with this because I have to try and make a lot of mistakes in order to get the right position. not quite a general solution.
library(ggplot2) library(raster) library(grid) img1 <- as.matrix(raster(system.file("external/rlogo.grd", package="raster"))) img1[img1>128] <- NA img1[img1>0] <- 0 image(img1) g1 <- rasterGrob(img1, interpolate=TRUE) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + ggtitle(" <- dat rLogo tho") + annotation_custom(g1,xmin = 1.2,1.6,35.5,38) gt <- ggplot_gtable(ggplot_build(p)) gt$layout$clip[gt$layout$name == "panel"] <- "off" grid.draw(gt)
source share