epstopdf changes the background color of R eps output files created with ggplot2 [closed]

StackOverflow https://stackoverflow.com/questions/16901867

  •  30-05-2022
  •  | 
  •  

質問

So here is something strange, at least for me. When I generate a eps file using export.eps from HH's export.eps method and then convert it using epstopdf, the background color of the .pdf file changes! But it only happens with plots made with ggplot2! E.g.:

library(ggplot2)
library(HH) # export.eps
qplot(rating, data=movies, weight=votes, geom="histogram") + theme_bw()
export.eps("result.eps")

EPS generated, nice

But when I convert result.eps to result.pdf using epstopdf result.eps, a strange blue background appears on the result.pdf:

Strange background resulting from epstopdf on a file generated from ggplot2

This does not happens when I use plot function:

plot(6:25,rnorm(20),type="b",xlim=c(1,30),ylim=c(-2.5,2.5),col=2)
export.eps("result_ok.eps")

Here I use epstopdf result_i.eps but the result_i.pdf has white background: Normal plot .eps Normal plot .pdf

Since I am using export.eps on both, I thought it has something to do with how ggplot2 composes the images, but as a noob in R, I do not know what to do to solve it.

役に立ちましたか?

解決

Ok, so, for my specific problem, that is, using ggplot2, I have solved it using ggsave command:

library(ggplot2)
library(HH) # export.eps
qplot(rating, data=movies, weight=votes, geom="histogram") + theme_bw()
ggsave("result.pdf")

Therefore I do not need to pass trough the epstopdf process and I also avoid using pdf command since I had the problem described on the answer/question posted by Dirk Eddelbuettel. The result.pdf file is nice and does not have the blue background. I was not aware about the ggsave command.

他のヒント

Is there a reason you are not using R itself to convert to pdf? See help(pdf) for more.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top