I wish to fill the entire plot space with a .png image, including the axis text and titles. However, I am only able to have the .png fill the plot space.
For example:
library(tidyverse)
library(png)
library(grid)
# Obtain an example image
Dog <- "https://static-2.gumroad.com/res/gumroad/2844939370808/asset_previews/ce2fdffe2166f4347cd5636bd2d91d2f/retina/Beagle_20Pup_20small.png"
# Download the file
download.file(Dog, destfile = dir <- paste0(tempdir(), "\\dog.png"))
# Read .png into R
dogimg <- readPNG(dir)
dog <- rasterGrob(dogimg, interpolate=TRUE)
# Attempt to plot
plot <- ggplot(mpg, aes(displ, hwy)) + geom_point() + annotation_custom(dog, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
Instead, I would rather the whole image fill the grey rectangle space, as per the below example:
plot + theme(
panel.background = element_rect(fill = "white"),
plot.margin = margin(2, 2, 2, 2, "cm"),
plot.background = element_rect(
fill = "grey90",
colour = "black",
size = 1
)
)
Thank you!