r - 为什么在 Sweave 中使用 includegraphics 时显示文本 'pdf 2'

标签 r pdf latex x11 sweave

如果使用以下 Sweave (R/LaTeX) 代码创建 pdf 文档,则在图的左上角将出现文本 pdf 2;请注意,这并未嵌入 png 中,但实际上是您可以突出显示的文本。

.Rnw中:

\begin{figure}[htb]
    \centering
<<fig=FALSE,echo=FALSE>>=
    png("test0.png",width=4,height=4,units='in',res=1200)
    plot(1)
    dev.off()
@
    \includegraphics{test0.png}
    \caption{Demonstration}
\end{figure}

然后在R中:

Sweave("report.Rnw") ; texi2pdf("report.tex")

我该如何解决这个问题?

我在 Ubuntu 上使用最新版本的 R

最佳答案

使用以下文件

\documentclass{article}
\begin{document}
\begin{figure}[htb]
    \centering
<<fig=FALSE,echo=FALSE>>=
    png("test0.png",width=4,height=4,units='in',res=1200)
    plot(1)
    dev.off()
@
    \includegraphics{test0.png}
    \caption{Demonstration}
\end{figure}

绘图前出现一条 null device 1 消息 它是生成绘图的 R 命令的输出。 您可以通过添加 results=hide 来抑制它。

<<fig=FALSE,echo=FALSE,results=hide>>=

您的消息略有不同,因为 dev.off() 返回当前设备的名称: 我的情况没有(这是一次新的 session ), 以及您之前打开(但未关闭)的 PDF 文件。

关于r - 为什么在 Sweave 中使用 includegraphics 时显示文本 'pdf 2',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19464132/

相关文章:

r - R中的每小时日期序列

r - 从adegenet R包中的genlight/genind对象中删除样本

jquery - 流式传输 byte[] 以将其作为 PDF (MVC3) 加载到 jquery 模式中

php - 如何使用 fpdf php 创建双条形图?

r - 避免代码块破坏 Knitr? (最好使用 block 选项)

scroll - 大型 Org 模式文件中的缓慢光标移动和 `org-do-latex-and-related` 函数

html - Shiny 的布局 - 如何添加页脚免责声明?

r - 计算每个子组的最短年份和最长年份之间的变化率

latex - 逐字环境中的自动换行

latex - latex 项目内联 “Missing $ inserted.”错误