出于纪录目的,我想要一些html输出中的绘图代码,而不是绘图.之后,我必须调用绘图代码,并在绘图中添加一些内容,但只能看到附加代码.我试过这个:
```{r non.finished.plotting, eval=FALSE}
plot(1,type="n")
```
Some explanatory text here in the output:
"This produces an empty plot, and we could now add some points to it manually."
```{r add.layer, fig.width=5, fig.height=5}
<<non.finished.plotting, echo=FALSE>>
points(x=rnorm(100,1,0.1), y=rnorm(100,0.8,0.1) )
```
Run Code Online (Sandbox Code Playgroud)
我在Yihui的发现了echo符号,但是当我编织它时,我在输出中收到一条错误信息.
## Error: plot.new has not been called yet
Run Code Online (Sandbox Code Playgroud)
我也尝试摆弄大块选项,但我找不到能满足我想要的组合.(对不起,这是非常基本的,但我没有找到类似这个例子的东西.)
对于研讨会随附的在线教程,我想强调网格包的使用(特别是如何使用视口).为此,我想逐步构建一个绘图(即chunk by chunk).在每个步骤/块之间,我想包括一些普通文本,以便更详细地解释每个步骤.
我如何告诉knitr不单独评估一个块,而是开始评估上一个块结束的位置?基本上,而不是我想要添加到前一个块的结果的块的新评估.
在下面的代码中,当编织为html时,我在.html输出中得到2个图.第一个显示第一个块的结果(粉红色矩形和一些文本),第二个显示第二个块的结果(蓝色矩形).我想要实现的是两个图 - 第一个显示第一个块的结果(如上所示),第二个图显示第一个块的结果+第二个块的结果(粉红色矩形内的蓝色矩形) ).基本上,我想在R控制台中运行时重现两个代码块的行为.蓝色矩形应放在粉红色矩形中,不能单独绘制.
这是第一块
```{r grid first vp, tidy = FALSE}
library(grid)
grid.newpage()
## draw a rectangle around the root vp and provide some text
grid.rect()
grid.text("this is the root vp", x = 0.5, y = 1, just = c("centre", "top"))
vp <- viewport(x = 0.5, y = 0.5,
height = 0.5, width = 0.5,
just = c("centre", "centre"))
pushViewport(vp)
grid.rect(gp = gpar(fill = "pink"))
grid.text("this is our first vp", x = 0.5, y = …Run Code Online (Sandbox Code Playgroud)