ggplot2:为什么半透明+ pdflatex导致比普通PDF字体重?

我遇到了一个问题,其中在R中进行pdf()编码,然后对ggplot2图像进行pdflatex编码会导致该图像与该页面在同一页面上的所有文本都被加粗,但仅当alpha

require("ggplot2")
"%_%" <- function(a, b) paste(a, b, sep="")
test <- function(filename, alpha)
{
  pdf(filename %_% "-fig.pdf")
  p <- ggplot(mtcars, aes(wt, mpg)) + geom_point(alpha=alpha)
  print(p); dev.off()

  latexDocument <- c(
    "\\documentclass{article}",
    "\\usepackage{Sweave}",
    "%\\pdfpageattr{/Group <</S /Transparency /I true /CS /DeviceRGB>>}",
    "\\begin{document}",
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    "\\begin{figure}",
    "\\includegraphics{" %_% filename %_% "-fig}",
    "  \\caption{Figure Caption}",
    "\\end{figure}",
    "\\end{document}")

  con <- file(filename %_% ".tex"); writeLines(latexDocument, con); close(con)
  system("pdflatex " %_% filename)
}

test("test1", 1)
test("test2", 0.3)

比较输出文件test1.pdf和test2.pdf,我注意到在Acrobat或Acrobat Reader中查看时,后者文档的字体较重。以前在here中讨论了该问题,但没有解决。

我似乎无法解决问题,这弄乱了我使用Sweave生成的报告的外观。有人对此有任何见识吗?我在Windows上使用R版本2.13.1。

最佳答案

尝试使用带有参数pdf()colormodel = "cmyk"函数?

require("ggplot2")
pdf("test_cmyk.pdf", colormodel = "cmyk")
ggplot(mtcars, aes(wt, mpg)) + geom_point(size = 3, alpha = 0.2) +
  opts(title = "cmyk, alpha = 0.2")
dev.off()
embedFonts("test_cmyk.pdf")

在我的环境(Win XP,Adobe Acrobat 9 Pro)中,它似乎比colormodel = "rgb"稍好。

10-08 07:16