显示Rmarkdown中新窗口图的图

问题描述 投票:1回答:1

我是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)
}

谢谢

r r-markdown
1个回答
0
投票

我想你只是不需要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()

```

test您可以检查/ figure文件夹中是否创建了数字。我和html_document一样输出。这有帮助吗?

© www.soinside.com 2019 - 2024. All rights reserved.