I need to produce a series of PDF plots with the Lattice package in R, with a text pointsize mandated by a journal in which it will be published.
Following the discussion here,, I can change the pointsize on a plot by plot basis:
library(lattice)
trellis.device("pdf", pointsize=30)
trellis.par.set(fontsize = list(text = NULL))
xyplot(1:10 ~ 1:10)
dev.off()
This yields the following plot:
But then I try to set a global option:
library(lattice)
lattice.options(default.theme = list(fontsize = list(text = NULL)))
trellis.device("png", pointsize=30)
xyplot(1:10 ~ 1:10)
dev.off()
And this doesn't yield the same results:
So how can I change the global pointsize for all the Lattice plots?
Your original question has been answered by jbaums, who suggests using
library(lattice)
lattice.options(default.theme = list(fontsize = list(text = 30)))
trellis.device("pdf")
xyplot(1:10 ~ 1:10)
dev.off()
which produces precisely what you want:
In the comments, however, you seem to be asking for a way to set defaults using lattice but then pass settings using dev.args
in knitr. The problem is that trellis.device(pdf)
calls default.theme
and my guess is that this overrides the pointsize = 30
argument you provide. However, if you want to reset this for individual lattice plots it's just a matter of calling par.settings
for each individual plot, like so:
\documentclass{article}
\begin{document}
<<setup>>=
library(lattice)
lattice.options(default.theme = list(fontsize = list(text = 8, points = 4)))
@
<<plot, dev='pdf'>>=
xyplot(1:10 ~ 1:10,
par.settings = list(fontsize = list(text = 25)))
@
<<plot2>>=
xyplot(1:10 ~ 1:10)
@
\end{document}