I have also asked this on tex.stackexchange.com:
This is a problem which I face with many many plots.
Lets say I create a ggplot2 plot, with a colourbar:
sample = ggplot(data=data.frame(x=runif(10),y=runif(10)),aes(x,y)) +
geom_point(aes(color=x))
Now when I export this to a tikz object via the following:
tikz("./figures/sample.tikz",width = 6,height=6/sqrt(2))
print(sample)
dev.off()
At around line 193 it contains the following:
\pgfimage[width= 14.45pt,height= 72.27pt,interpolate=true]{sample_ras1}};
which is referring to a raster image of the colourbar.
Now the problem is, this tikz plot is in the images folder, which is a subdirectory to the root document, and therefore, for this to be plotted correctly in a latex document, the above pgfimage line should be as follows:
\pgfimage[width= 14.45pt,height= 72.27pt,interpolate=true]{figures/sample_ras1}};
How can I ensure that the image is being picked up relative to the tikz file, NOT the root .tex file?
I could go through and manually add the small change, but like I said, I have many many images and this would be tedious. One option is to simply write the tikz files to the root folder, however, I don't particularly want to pollute the root folder with countless images.