ggplot2: Why Does Semi-Transparency + pdflatex Cause Heavier-Than-Normal PDF Fonts?
I’ve run into a problem where pdf()ing in R and then pdflatex-ing a ggplot2 image causes all of the text on the same page as the image to become emboldened, but only when alpha < 1. Here’s a minimal example in R:
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)
Comparing the output files test1.pdf and test2.pdf, I notice that the latter document has heavier fonts when viewed in Acrobat or Acrobat Reader. The problem has been discussed here before, but to no resolution.
I can’t seem to solve the problem, which messes up the look of reports I generate with Sweave. Does anyone have any insight into it? I’m using R version 2.13.1 on Windows.
Try the
pdf()function with an argument,colormodel = "cmyk"?It seems to be slightly better than
colormodel = "rgb"in my environment (Win XP, Adobe Acrobat 9 Pro).