In this example, let’s see how to add an image watermark to ggplot. Can either use png or jpeg to load a png or a jpeg.
library(ggplot2)
df <-
data.frame(
key = c("Compliance", "Information Technology"),
budget = c(25000, 15000)
)
img <- png::readPNG("./watermark.png")
## Warning in png::readPNG("./watermark.png"): libpng warning: iCCP: known
## incorrect sRGB profile
rast <- grid::rasterGrob(img, interpolate = T)
Here is the example.
ggplot(data = df) +
annotation_custom(rast, ymin = 24000, ymax = 27000, xmin = 2) +
geom_bar(aes(x=key, y = budget), stat = "identity", alpha = 0.8)
ggplot(data = df) +
annotation_custom(rast, ymin = 24000, ymax = 27000, xmin = 2) +
geom_bar(aes(x=key, y = budget), stat = "identity", alpha = 0.8) +
facet_wrap(~key)
So far I couldn’t find another way to put an image that will give an easier way to set the size and placement of the image.