r markdown 输出到 pdf:停止分解代码块

丹妮尔

我正在将 r markdown 文件打印为 pdf。我尝试了各种输出规格,但该图一直显示在段 [1] 和 [2] 的中间。

我希望将所有代码显示为一个块,并稍后在文档中调用该图。

```{r, include=TRUE, results='hide'}
# [1] There is code up here

# [plot interrupts the code chunk here] Scatter plot

plot1 = plot(df$var1, df$var)

# [2] More code below this point
```
彼得

使用块选项fig.show = 'hold'显示块末尾的块产生的所有图。这是一个示例 .Rmd 文件和输出。

---
title: Stop Plot Breakikng Up Code Chunk
output: pdf_document
---

The key is to use the chunk option `fig.show = 'hold'` so that all plots from
the chunk will will displayed at the end of the chunk.

```{r setup, include = FALSE, cache = FALSE}
library(knitr)
opts_chunk$set(fig.show = "hold")
```

We'll use the `mtcars` data set for the example.

```{r plot1, include = TRUE, results = "hide"}
mean(mtcars$wt)
mean(mtcars$mpg)

plot(mtcars$wt, mtcars$mpg)

var(mtcars$wt)
```

End of example.

在此处输入图片说明

编辑:

另一种更接近我认为您正在寻找的解决方案是使用ref.label重用代码块。

---
title: Stop Plot Breaking Up Code Chunk
output: pdf_document
---

The key is to use the chunk option `fig.show = 'hold'` so that all plots from
the chunk will will displayed at the end of the chunk.

```{r setup, include = FALSE, cache = FALSE}
library(knitr)
opts_chunk$set(fig.show = "hold",
               collapse = TRUE)
```

We will use the `mtcars` data set for the example.

```{r all_code}
```{r mean_code, ref.label = "means", echo = TRUE, results = "hide"}
```{r plot1_code, ref.label = "plot1", echo = TRUE, fig.show = "hide", fig.keep = "none"}
```{r var_code, ref.label = "var_wt", echo = TRUE, results = "hide"}
```


Description of a plot

```{r "plot1", echo = FALSE}
plot(mtcars$wt, mtcars$mpg)
```

More text.

Below here, chunks that are evaluated, but not shown.

```{r means, include = FALSE}
mean(mtcars$wt)
mean(mtcars$mpg)
```

```{r var_wt, include = FALSE}
var(mtcars$wt)
```

End of the example.

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

条件标题的标题取决于代码块R Markdown的输出

来自分类Dev

在最终输出中显示R markdown块

来自分类Dev

R markdown pdf,某些输出不会显示

来自分类Dev

R markdown编织到Pdf问题:r代码结果与pdf输出不同

来自分类Dev

R Markdown HTML代码块和输出中缺少水平滚动条

来自分类Dev

调整PDF输出中的R Markdown标题位置

来自分类Dev

R Markdown - 删除 pdf 输出中的左侧标题

来自分类Dev

R Markdown标签悬停输出

来自分类Dev

R markdown ioslides代码块的增量模式

来自分类Dev

R Markdown链接使用代码块

来自分类Dev

当我尝试将r-markdown导出到pdf时出现错误

来自分类Dev

将R Markdown转换为pdf时的受防护代码块

来自分类Dev

R Markdown-自动块?

来自分类Dev

R块内的Markdown语言

来自分类Dev

R Markdown-变量输出名称

来自分类Dev

R Markdown,循环输出测试结果

来自分类Dev

正确的R Markdown代码组织

来自分类Dev

TypeScript - 停止输出到文件?

来自分类Dev

R Markdown文本中的换行符(不是代码块)

来自分类Dev

R-markdown块中的一行的HTML代码

来自分类Dev

R markdown:在评估之前从代码块访问变量

来自分类Dev

R Markdown,SQL代码块生成语法错误

来自分类Dev

R-markdown块内的HTML代码(单行)

来自分类Dev

将图形分开打印到PDF文件并同时输出R Markdown

来自分类Dev

输出到pdf无法与R中的ReferenceClasses方法一起使用?

来自分类Dev

R markdown PDF文件中的内联代码未正确显示

来自分类Dev

将R输出导出到Excel

来自分类Dev

将R输出导出到Excel

来自分类Dev

R 闪亮的映射输出到输入