R 清理tikz设备的晶格轴标签

R 清理tikz设备的晶格轴标签,r,knitr,lattice,tikz,R,Knitr,Lattice,Tikz,我正试图使用knitr和tikz设备将latticecontourplot编织成PDF文档,但编译时getMetricsFromLaTeX(TeXMetrics)中出现错误。以下是最小可重复性示例: \documentclass{article} \begin{document} <<contourplot,dev='tikz',echo=FALSE>>= library(lattice) library(RCurl) x <- getURL("https://

我正试图使用
knitr
tikz
设备将
lattice
contourplot
编织成PDF文档,但编译时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}
\documentclass{article}
\开始{document}
=
图书馆(格子)
图书馆(RCurl)

x正如安迪·克利夫顿(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}
\documentclass{article}
\开始{document}
=
图书馆(GG2)
图书馆(比例尺)
图书馆(RCurl)

x要清理轴标签,请按以下方式修改
scales
参数:

# e-notation (like ggplot2)
scales = list(y = list(log=10, at=10**seq(5, 15, 5))))


有没有不使用ggplot的原因?这对knitr很有效。例如:
=
,然后是绘图:
ggplot(blah)+theme_bw(base_size=8)
。我尝试了
ggplot
(一个我比
lattice
加载更多经验的包),但从未让绘图看起来像上面的一样。但在玩了一段时间之后,也许这还为时过早。这几乎正是我想要的:你可以使用
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)))
,但是,既然你的解决方案实际上回答了原来的问题,你想把它作为一个答案发布并收集赏金吗?注意自我回答问题,而不是发表评论!不过很高兴这起作用。对不起,我不是有意要偷你的信用。根据你的评论,我在几分钟内就搞定了细节,并认为发布解决方案是最简单的。我很乐意删除我的答案,让你转发并奖励你。不用担心,只是开玩笑。我不知道你是怎么做到的,但你做到了,所以一切都是你的。
scales = list(y = list(log=10, at=10**seq(5, 15, 5),
              label=sprintf("$10^{%d}$", seq(5, 15, 5))))