简体   繁体   English

在Rmarkdown中显示来自新窗口图的图

[英]Display plot from new window plot in Rmarkdown

I am new to rmarkdown and I would like to show a plot which is normally produced in a new window. 我是rmarkdown的新手,我想显示一个通常在新窗口中生成的图。 This plot is called from a function that displays it in a new window using plot.new() and dev.new() and also adds several plots in that window. 从一个函数调用此图,该函数使用plot.new()和dev.new()在新窗口中显示该图,并在该窗口中添加多个图。 How can I return this to the report? 如何将其返回到报告中?

the following does not return the plots... 以下内容不返回情节...

```{r  fig.keep='all', fig.width=10, fig.height=5}

Draw_matrix_plots(data)

```

and the function skeleton I am calling which draws four plots in a new window: 和我正在调用的函数框架,它在一个新窗口中绘制了四个图:

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

Thanks 谢谢

I think you just don't need the dev.new(), the following code produce 我认为您只是不需要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()

```

测试 You can check that the figures are created in the /figure folder. 您可以检查是否在/ figure文件夹中创建了图。 I have the same with html_document as an output. 我有html_document作为输出。 Does that help ? 有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM