I created a barchart in ggplot2 using the following code.
g <- ggplot(mpg, aes(class))
# Number of cars in each class:
g + geom_bar()
I created an image object using the code such as
img <- png::readPNG("./watermark.png")
rast <- grid::rasterGrob(img, interpolate = T)
Now I am trying to paste this image onto the plot using a command such as
g + annotation_custom(rast, xmin=-Inf, xmax=Inf,ymin=-Inf,ymax=Inf)
which creates the following plot
https://i.stack.imgur.com/XdHBe.jpg
I understand that the x and y co-ordinates in annotation_custom are relative to the data plotted on the x and y axis.
In my case I have discrete data on the X Axis and want to paste this image in the top right corner, please can someone advise how I can do that.