I am trying to plot a theoretical function y = f(x) of my making over a background of a published PDF histogram, to try to get them to match. In other words, I am trying to see if my function generally matches data already published. The functions are things like f(x) = C x^2 exp(-kx) and such. The published data are things like this...
A possible solution is to use cowplot to overlay the image onto a ggplot plot, set the axis limits carefully so they coincide, and plot your function over time.
I read the vignette on cowplot. I think we are getting close to a solution but I don't think this is it yet. In the vignette it looks like it calls up and displays images from a system folder or file via the code :
logo_file <- system.file("extdata", "logo.png", package = "cowplot")
ggdraw(p) +
draw_image(logo_file, x = 1, y = 1, hjust = 1, vjust = 1, width = 0.13, height = 0.2)
It looks like it adds saved data to the plot plus a png file of the cowplot logo. However, at this stage of my Rstudio career I can't see how it would load a pdf or png of my choice.
There has got to be a way to plot over an image file by some plotting program somewhere. There are hundreds of such images on the web. Just do a search for say, histogram test function, and then switch to google image search and you will see plenty. I doubt it if all those have the histogram and the test function from the same plotting program.