I need to plot some simple line plots along with an image. However, the image's left and right side need to align to both the left and right end of the line plot.
My code produces the following graph:
However, I need the graph to look like this (dash lines on the edge only for reference):
As such, I need a way to both move and scale the image along the x-axis to accomplish this.
The code I am currently using is:
library(tidyverse)
library(grid)
library(gridExtra)
library(cowplot)
library(magick)
df <- tibble(Long_Name_For_X= -10:10,Long_Name_For_Y = x^2,Long_Name_For_Z= x)
testImage <- image_read(file.path("C:/index.jpg"))
p1 <- df %>%
gather(variable,value,-Long_Name_For_X) %>%
ggplot(aes(x=Long_Name_For_X,y=value,color=variable)) +
geom_line()
p2 <- ggdraw() + draw_image(testImage)
plot_grid(p1,p2,ncol=1,align = "v", axis = "l")