I'm trying to plot multiple dataframe with smooth line using ggplot() or stat_smooth() with a png as a background.
I have three dataframes
data1 <- data.frame(Max.x, Max.y)
data2 <- data.frame(Med.x, Med.y)
data3 <- data.frame(Min.x, Min.y)
and a picture(png) file
mypng <- readPNG("picture.png")
I found that with stat_smooth(span=0.4) it will create a smooth line that goes through all the points in the dataframe.
Now I'm trying to plot the three smooth lines on mypng
I've tried couple things.
ggplot(data1, aes(x=Max.x, y=Max.y))+scale_x_continuous(limits = c(126,129))+scale_y_continuous(limits = c(37.5, 38.5))+ annotation_raster(mypng, xmin=126, xmax=129, ymin=37.5, ymax=38.5)+stat_smooth(span=0.4)
Same goes for data2 and data3. This plots each line on a png but I can't find a way to get all three to lines on a same png.
Also, note that the plot has to have set x,y max and min b/c my data falls between those coordinates.
Another thing I tried:
ggplot()+annotation_raster(mypng, xmin=126, xmax=129, ymin=37.5, ymax=38.5)+stat_smooth(data=data1, aes(x=Max.x, y=Max.y), span=0.4)+stat_smooth(data=data2, aes(x=Med.x, y=Med.y), span=0.4)+stat_smooth(data=data3, aes(x=Min.x, y=Min.y), span=0.4)+scale_x_continuous(limits=c(126,129))+scale_y_continuous(limits=c(37.5,38.5))
This plots all three smoothlines. However the picture doesnt show up.
I am now stuck... I can get three different plots on mypng. And I can get all three plots but not on mypng. How can I get all three lines on mypng?