Lyx and Latex work splendidly with .eps images. But when I export a scatter plot with a smoothing curve from Rstudio, the points are lost and the plot is delivered with only the curve.
The two save methods I have tried are:
In Rstudio, choose "Export" from the drop down menu in the image field and save as .eps. Interestingly, the plot appears as it should in the Rstudio preview.
Preface the plot code with
setEPS()
followed bypostscript()
, with the desired dimensions and so on, followed by the plot call usinglibrary(ggplot2)
, e.g.ggplot()
.
At first I thought the problem may be elsewhere. But then I saved a .eps in Mathematica and there was no issue.
I snooped around the internet and found other issues with saving .eps in R, but none dealt with lost information.
What exactly is going on?
I should mention that .eps imager render in Lyx loads better than any other format, so I insist on using .eps.
Many thanks in advance for your input, I cannot yet up-vote them.
EDIT
So far as I can tell, this question was a dead end due to EPS being unable to keep transparency ribbons. (See comments.) By request I posted code that highlights the problem.
Say you have the data data <- data.frame(replicate(2,rnorm(1000)))
. You want to plot them, but there are so many points, so you add a transparency parameter. In addition, you add a fitted line with a confidence interval. Your code is:
ggplot(data = data, aes(x=X1, y=X2)) +
geom_point(alpha=0.4) +
stat_smooth(se=T, method="lm")
Looks good. But if you try to save the plot as an EPS, all you will see when you later open the saved file is an empty plot object save for the blue fitted line.
Lesson is, if you insist on EPS, you must turn off transparency ribbons. In this case, set alpha=1
(or just don't include it) and se=FALSE
.
ggplot()
. A common error message says: "semi-transparency is not supported on this device: reported only once per page" – Handtomouthgeom_smooth()
creates a ribbon with transparency (alpha). The eps device doesn't support transparency. To fix this, you need to setalpha=1
in thegeom_smooth()
. – Ineslta