如何在没有原始降价输出的情况下使用编织块将元素添加到绘图中? [英] How to add elements to a plot using a knitr chunk without original markdown output?
问题描述
出于记录目的,我想要html输出中用于绘图的一些代码,而不是绘图.稍后,我必须调用绘图代码,并在绘图中添加一些内容,但只能看到其他代码.我尝试过:
For documentary purposes, I want some code for a plot in the html-output, but not the plot. Later, I have to call the plotting code, and add something to the plot, but only seeing the additional code. I tried this:
```{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) )
```
我在 Yihui的处找到了回显符号,但是当我将其编织时,我收到一条错误消息输出.
I have found the echo-notation at Yihui's, but when I knit this, I get an error message in the output.
## Error: plot.new has not been called yet
我还尝试摆弄 chunk选项,但是我找不到能满足我需求的组合. (对不起,这是非常基本的内容,但是我没有找到类似此示例的内容.)
I also tried fiddling with the chunk options, but I could not find a combination which does what I want. (Sorry, this is very basic, but I did not find something quite like this example.)
推荐答案
<<>>
中的块引用不考虑块选项,因此<<non.finished.plotting, echo=FALSE>>
将不起作用.您可以做的是将块选项echo
移回主块,如下所示:
Chunk references in <<>>
do not respect chunk options, so <<non.finished.plotting, echo=FALSE>>
will not work. What you can do is to move the chunk option echo
back to the main chunk like this:
```{r add.layer, fig.width=5, fig.height=5, echo=-1}
<<non.finished.plotting>>
points(x=rnorm(100,1,0.1), y=rnorm(100,0.8,0.1) )
```
echo=-1
表示不回显第一个表达式(如已记录).这可能就是您想要的:
echo=-1
means do not echo the first expression (as documented). This is probably what you want:
这篇关于如何在没有原始降价输出的情况下使用编织块将元素添加到绘图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!