I'm trying to knit a lattice
contourplot
into a PDF document using knitr
and the tikz
device but am getting an Error in getMetricsFromLaTeX(TeXMetrics)
on compile. Here's the minimal reproducible example:
\documentclass{article}
\begin{document}
<<contourplot,dev='tikz',echo=FALSE>>=
library(lattice)
library(RCurl)
x <- getURL("https://dl.dropboxusercontent.com/u/3966900/likelihoods.csv")
likelihoods <- read.csv(text=x)
cutoffs <- c(- Inf,-2700,-1497,-1486.6,-1486.3,-1486.286,-1486.28513,-1486.285082,-1486.28508033,-1486.285080237, Inf)
contourplot(ll ~ var1*var2,
data = likelihoods,
scales = list(y = list(log = 10)),
at=cutoffs,
label.style='align',
labels=as.character(cutoffs),
xlab='$\\\\\\sigma$')
@
\end{document}
The whole thing works if I remove the scales
line (I assume it's the ^
in the axis labels that trips tikz
up?) but looks like shit.
It also works if I add sanitize=TRUE
to the chunk options and remove two backslashes from the xlab
string. In this case, however, the axis label also gets sanitized and I don't get a LaTeX-typeset axis label.
How do I get all of this to work?