我是rmarkdown的新手,我想展示一个通常在新窗口中生成的情节。该图从一个函数调用,该函数使用plot.new()和dev.new()在一个新窗口中显示它,并在该窗口中添加几个图。我该如何将其返回报告?
以下不返回图表...
```{r fig.keep='all', fig.width=10, fig.height=5}
Draw_matrix_plots(data)
```
和我调用的函数框架在新窗口中绘制四个图:
Draw_matrix_plots <- function(data){
plot.new()
dev.new(width=7, height=8)
layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE),heights=c(3,3))
hist(data$A)
hist(data$B)
hist(data$C)
hist(data$D)
}
谢谢
我想你只是不需要dev.new(),下面的代码就产生了
---
title: "Test"
ouptut: pdf_document
---
# R code
```{r fig.keep='all', fig.width=10, fig.height=5}
Draw_matrix_plots <- function(){
layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE),heights=c(3,3))
hist(rnorm(100))
hist(rnorm(100))
hist(rnorm(100))
hist(rnorm(100))
}
Draw_matrix_plots()
```