【问题标题】:include tikz commands via Sexpr通过 Sexpr 包含 tikz 命令
【发布时间】:2016-12-31 19:55:44
【问题描述】:

我想使用 tikz 在 Sweave 创建的自动报告中实现基本图形。因此,我创建了一个 R 函数,根据数据返回 tikz 命令。我的代码与此类似:

<<echo=FALSE>>=
y <- 20
code <- cat(paste("\\draw (0pt, ",y,"pt) circle (5pt)", sep=""))
@
\begin{tikzpicture}
\Sexpr{code}
\end{tikzpicture}

这不起作用...我得到的是字符串而不是绘图。

【问题讨论】:

    标签: r latex sweave tikz


    【解决方案1】:

    不要使用\Sexpr,只需将chunk放在tikzpicture环境中,并添加chunk选项results=tex即可。例如,

    \begin{tikzpicture}
    <<echo=FALSE, results=tex>>=
    y <- 20
    cat(paste0("\\draw (0pt, ",y,"pt) circle (5pt)", sep=""))
    @
    \end{tikzpicture}
    

    这未经测试,因此您可能需要稍微调整一下。

    【讨论】:

      猜你喜欢
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2018-04-29
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多