【问题标题】:epstopdf changes the background color of R eps output files created with ggplot2 [closed]epstopdf 更改使用 ggplot2 创建的 R eps 输出文件的背景颜色 [关闭]
【发布时间】:2025-12-29 05:25:06
【问题描述】:

所以这里有些奇怪,至少对我来说是这样。当我使用 HH 的 export.eps 方法中的 export.eps 生成 eps 文件,然后使用 epstopdf 转换它时,.pdf 文件的背景颜色会发生变化!但它只发生在用 ggplot2 制作的情节上!例如:

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

但是当我使用 epstopdf result.eps 将 result.eps 转换为 result.pdf 时,result.pdf 上会出现一个奇怪的蓝色背景:

当我使用plot 函数时不会发生这种情况:

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

这里我使用epstopdf result_i.eps,但 result_i.pdf 有白色背景:

由于我在两者上都使用export.eps,我认为这与 ggplot2 如何组成图像有关,但作为 R 中的菜鸟,我不知道如何解决它。

【问题讨论】:

    标签: r pdf ggplot2 eps


    【解决方案1】:

    好的,所以,对于我的具体问题,即使用ggplot2,我已经使用ggsave命令解决了:

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

    因此,我不需要通过 epstopdf 进程,并且我也避免使用 pdf 命令,因为我遇到了 Dirk Eddelbuettel 发布的答案/问题中描述的问题。 result.pdf 文件很好,没有蓝色背景。我不知道ggsave 命令。

    【讨论】:

      【解决方案2】:

      您不使用 R 本身转换为 pdf 是否有原因?请参阅help(pdf) 了解更多信息。

      【讨论】:

      • 首先,感谢您的回答/问题。您的问题的答案将取决于另一个问题。起初,pdf 命令给了我一个 700x700 的文件。它不像 export.eps 那样导出具有当前设备大小的文件(我的意思是,当我调整输出屏幕的大小时,export.eps 给了我当前大小)。然后我使用了pdf的宽度和高度参数。尺寸很好,但标签和轴消失了!查看漂亮的图片imgur.com/dgoYZdp 和使用pdf的图片imgur.com/qp4o3MJ
      最近更新 更多