我正在尝试使用lattice
和contourplot
设备将knitr
tikz
编入PDF文档,但在编译时会得到Error in getMetricsFromLaTeX(TeXMetrics)
。这是最小的可重复示例:
\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}
如果我删除scales
行(我假设它是^
行的tikz
中的sanitize=TRUE
,那么整个过程都有效。但看起来像狗屎。
如果我将xlab
添加到块选项并从{{1}}字符串中删除两个反斜杠,它也可以工作。但是,在这种情况下,轴标签也会被消毒,我没有得到LaTeX排版的轴标签。
如何让所有工作?
答案 0 :(得分:1)
正如Andy Clifton在评论中建议的那样,使用ggplot
做这件事似乎比让它与格子一起工作要容易得多:
\documentclass{article}
\begin{document}
<<contourplot,dev='tikz',echo=FALSE,warning=FALSE>>=
library(ggplot2)
library(scales)
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)
v <- ggplot(likelihoods, aes(var1, var2, z = ll))
v <- v + stat_contour(breaks=cutoffs)
v <- v + scale_y_continuous(trans=log10_trans(),
breaks=c(1e-5,1e0,1e5,1e10,1e15,1e20),
expand = c(0, 0))
v <- v + scale_x_continuous(limits = c(-3, 5),
expand = c(0, 0))
v <- v + theme_bw()
v <- v + ylab('$\\sigma$')
v
@
\end{document}
答案 1 :(得分:1)
要清理轴标签,请按以下方式修改scales
参数:
# e-notation (like ggplot2)
scales = list(y = list(log=10, at=10**seq(5, 15, 5))))
或
scales = list(y = list(log=10, at=10**seq(5, 15, 5),
label=sprintf("$10^{%d}$", seq(5, 15, 5))))