I am trying to troubleshoot a noticeable difference in font size when comparing plots generated for a knitr
document. HTML/markdown output appears to be what I would consider the correct size while the PDF/Latex output is approximately 2-4 pts larger (e.g., if I was expecting 12pt, the output is closer 14 or 16 pts). Note the issue seems to be limited to the plot/figure text and doesn't seem to manifest with other text in the output document.
The simplest way for me to demonstrate this is with the default content that RStudio (version 0.99.329) populates when a new *.Rmd
file is created. A side-by-side comparison is available via this link. To my eye, the HTML version is properly sized and the PDF/Latex version is not.
To my knowledge, I don't have any custom settings within my .Rprofile or other locations that could be impacting this issue. I have tried disabling/enabling pdf crop and that does not seem to impact the issue either. I have duplicated the issue on a colleagues machine (also running OS X and the same version of RStudio).
Outside of the rmarkdown
framework (i.e., just running R code) there does not appear to be such a difference between PDF and PNG output. For example, the following code produces output that is fairly similar:
library(ggplot2)
r <- ggplot(data = diamonds,
aes(x = carat, y = price, color = cut, group = cut))
r + geom_smooth(size = 2) +
ggtitle("Plant growth with\ndifferent treatments")
ggsave(file="test.pdf")
ggsave(file="test.png")
Given that this code above produces output plots that are fairly similar, I'm suspicious the issues I'm seeing are related to knitr or the rmarkdown/pandoc conversion process.
So, my main question is whether the level of differences I'm seeing between output formats is expected? Am I the only one? Is it unique to my system?
If it is expected behavior, how are folks reconciling the issue? For ggplots, I've been using theme_bw(8.5)
to downscale the fonts for PDF/latex output. This works, but it adds another level of complexity when creating output for multiple platforms/uses from the same *.Rmd
file ... one of the key benefits of rmarkdown
.
Specifications of my setup and system
- OS X 10.10.2, MacBook Pro (Retina, 15-inch, Early 2013)
- RStudio Version 0.99.329
- R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
- rmarkdown 0.5.1
- pandoc 1.13.1
dev=pdf
for html-files, it cannot be displayed any more, but the generated file shows the same font size as with pdf generation. If I manually setdev='png'
for pdf-files, I get theerror: unused argument (pdf=list(useDingbats=FALSE)
, whicht might have something to do with thedev.args
-chunk-option. Here I think might also be the solution... – Julian