使用 pgfSweave 和 tikzDevice 时遇到问题

使用 pgfSweave 和 tikzDevice 时遇到问题

本·博克的pgfSweave我开始使用和的建议tikzDevice。我正在努力将R图表导入 LaTeX。

这是我的pgfSweave Rnw文件代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{Sweave}
\usepackage[margin=1in]{geometry}

\title{Minimal pgfSweave Example}
\author{Cameron Bracken}

\begin{document}

<<setup,echo=F>>=
setCacheDir("cache")
options(keep.space=TRUE)
@


\maketitle
This example is identical to that in the Sweave manual and is intended to
introduce pgfSweave and highlight the basic differences. Please refer to
the pgfSweave vignette for more usage instructions.
We embed parts of the examples from the \texttt{kruskal.test} help page
into a \LaTeX{} document:

<<data,cache=T,tidy=T>>=
# hey, a comment
data(airquality)
print(kruskal.test(Ozone ~ Month, data = airquality )) # and another
@

\noindent which shows that the location parameter of the Ozone distribution varies
significantly from month to month. Finally we include a boxplot of the data:

\begin{figure}[!ht]
  \centering
  %notice the new options
  {\pgfkeys{/pgf/images/include external/.code=
    {\includegraphics[width=3in]{#1}}}

    <<boxplot, echo=T, fig=T, width=3, height=3, tikz=T, external=T, highlight=T>>=
      boxplot(Ozone ~ Month, data = airquality,
        main='Ozone distribution',xlab='Month',ylab='Concentration')
     @
   }% this brace ends the effect of `include external'
  \caption{This is from pgfSweave. Text is typset by \LaTeX\ and so matches the
           font of the document.}
\end{figure}

\end{document}

产生

pgfSweave 输出

代码tikzDevice Rnw

\documentclass{article}
\usepackage{tikz}
\usepackage[nogin]{Sweave}

\begin{document}

<<echo=FALSE>>=
library(tikzDevice)
@

\begin{figure}[ht]
  \centering

  <<inline, echo=FALSE, results=tex>>=
  tikz(console=TRUE, width=5, height=5)
  x <- rnorm (100)
  plot(x)
  dummy <- dev.off()
  @

  \caption{caption}
  \label{fig:inline}
\end{figure}

\end{document}

产生

tikzDevice 输出

我的问题是:我遗漏了什么? 这两个Rnw代码都没有生成可包含在 LaTeX 文档中的R图表pdf。 任何帮助都将不胜感激。

答案1

在两种情况下,Sweave 块都不应缩进。

当 Sweave 驱动程序(R 的一部分)解析输入文件时,它会将其识别为以<<开头、以 结尾的R 代码块@。由于您的<<不在行首,因此这些块永远不会作为 R 代码运行,也不会生成任何图表。

相关内容