0

我正在尝试使用和设备将 alattice contourplot编入 PDF 文档,但正在编译。这是最小的可重现示例:knitrtikzError 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字符串中删除两个反斜杠,它也可以工作。然而,在这种情况下,轴标签也会被清理,我没有得到 LaTeX 排版的轴标签。

我如何让所有这些工作?

4

2 回答 2

1

正如 Andy Clifton 在评论中建议的那样,这样做ggplot似乎比使用 lattice 容易得多:

\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}
于 2014-08-22T00:20:35.990 回答
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))))
于 2014-08-27T11:21:28.463 回答