4

I was under the impression that if I used the tikz device (that I am trying for the first time today) that graphic text would be consistent with the text in the rest of my Latex document (generated using Knitr / RStudio). However, what I am seeing (or trying to see) (with and without tikz) is very small font in my graphics. Sample code to demonstrate:

\documentclass[12pt,a4paper]{article}

\begin{document}

Here is some text

<<eg, dev='tikz', size='normalsize',fig.width=12, fig.height=5, fig.cap="ggplot theme not adjusted", echo=FALSE, message=FALSE, warning=FALSE>>=
require(ggplot2)
ggplot(cars) + geom_histogram(aes(speed), binwidth=1)
@


<<egWithTheme, dev='tikz', size='normalsize',fig.width=12, fig.height=5, fig.cap="ggplot element text size 30", echo=FALSE>>=
ggplot(cars) + geom_histogram(aes(speed), binwidth=1) + theme(text=element_text(size=30))
@

<<increasing dpi, dev='tikz', size='normalsize',fig.width=12, fig.height=5, dpi=300, fig.cap="dpi set to 300", echo=FALSE>>=
ggplot(cars) + geom_histogram(aes(speed), binwidth=1)
@

\end{document} 

Screenshots of the three resulting figures: enter image description here enter image description here

What is the recommended approach for achieving consistency between font sizes in graphics and the document?

Thanks.

user1420372
  • 2,077
  • 3
  • 25
  • 42
  • Built-in `theme()` layers like `theme_bw()` can take point sizes as arguments and scale up/down your labels. Try adding `+ theme_bw(8)` to your plot… – Andrew May 02 '14 at 02:26
  • @Andrew, no that doesn't help. Thanks anyway – user1420372 May 02 '14 at 02:30
  • okay the first option works if I adjust my "cm" measurements to inches, i.e., by using fig.width=4.72, fig.height=1.96. – user1420372 May 02 '14 at 03:19
  • 8
    Use same values for fig.width/fig.height and out.width/out.height, e.g., `fig.width=4, fig.height=3, out.width="4in", out.height="3in"` – kohske May 02 '14 at 04:24
  • 1
    @kohske is right, your plots are produced with a size much larger than the paper that LaTeX uses; knitr has some built-in macro to prevent such large images from flooding outside the page, but that means resizing the image. I think you'll find that a maximum width of about 7 inches should not have to be scaled down. – baptiste May 02 '14 at 14:02
  • 1
    @kohske Yep, that is exactly correct. – Yihui Xie May 03 '14 at 06:22

0 Answers0