I usually embed numerous R
plots in my TeX documents. knitr
is very handy in helping me producing plots using the same font family of the TeX document. But a different problem of consistency is given by the font size: still I haven't found a way to maintain the same font size independently from the size of the containing box. For instance I might have a plot that extends horizontally over 90 percent of the paper width and then another that will only extends over 45 percent; usually this will result in plots with different font sizes. I can of course go back to the R
script and tweak the size values until I get the right size but I wonder if there's a smarter solution to set the font size of the plots for the whole document without modifying the plots' source scripts.
-
You might want to take a look at [r-forge.r-project.org/projects/tikzdevice/](tikzdevice).– AndreasCommented Oct 30, 2013 at 8:06
-
3The original maintainer of tikzDevice is no longer actively maintaining this package, so we are trying to take it over: github.com/yihui/tikzDevice (You can install from rforge.net/tikzDevice) knitr has built-in support for tikzDevice; see example 059 for an example: github.com/yihui/knitr-examples For more: yihui.name/knitr/demo/graphics– Yihui XieCommented Nov 3, 2013 at 17:49
-
1Great news you are taking the package over. Communities of users usually don't say thanks, but I do.– FrancescoCommented Nov 3, 2013 at 23:24
Add a comment
|
1 Answer
Have you considered the tikzDevice-Package for R?
It lets you create *.tex files to import into latex like this:
library(tikzDevice)
options(tikzMetricPackages = c("\\usepackage[utf8]{inputenc}",
"\\usepackage{amssymb,amsmath,amsfonts}"))
tikz("your directory/graph.tex", width=3,height=3)
plot(runif(10))
legend("topright","this text should not scale")
dev.off()
Then you can input it in your latex-code, using the package "tikz", where you can use \tikzset to scale the picture. The fontsize stays the same.
\usepackage{tikz}
\begin{figure}
\centering
\tikzset{every picture/.append style={scale=0.4}}
\include{graph}
\caption{a nice graph}
\label{graph}
\end{figure}
`