如何在 DiagrammeR 包中调整 grViz 对象的大小

How do you resize grViz object in the DiagrammeR package

正在努力调整 DiagrammeR 包中 grViz 对象的大小。例如,我希望对象的尺寸为 18 厘米宽和 14 厘米高。当我尝试包中的高度和宽度属性时,我似乎没有得到正确的测量结果。 或者有没有一种方法可以将 grViz 保存为图像,这样就可以在 Rmarkdown 中提取该图像?

代码如下:

---
title: "Flowchart on Trial"
author: "Moses Otieno"
date: "25/05/2021"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(DiagrammeR) # Flowchart
```


```{r test}
nodedata2 <- list(a = 1000, b = 940, c=900, d= 500, e=400, f = 230, g = 260, h = 10, i = 180, j = 190, k = 30 )

 grViz("digraph flowchart {
      # node definitions with substituted label text
      node [fontname = Helvetica, shape = rectangle]        
      tab1 [label = '@@1']
      tab2 [label = '@@2']
      tab3 [label = '@@3']
      tab4 [label = '@@4']
      tab5 [label = '@@5']
      tab6 [label = '@@6']
      tab7 [label = '@@7']
      tab8 [label = '@@8']
      tab9 [label = '@@9']
      tab10 [label = '@@10']
      tab11 [label = '@@11']


      # edge definitions with the node IDs
      tab1 -> tab2;
      tab2 -> tab3;
      tab3 -> {tab4 tab5}; 
      tab4 -> {tab6 tab7 tab8};
      tab5 -> {tab9 tab10 tab11};

      }

      [1]: paste('Sampled n=', nodedata2$a,  'participants')
      [2]: paste('Contacted ', nodedata2$b)
      [3]: paste('Enrolled n=', nodedata2$c)
      [4]: paste('Male  n=',nodedata2$d)
      [5]: paste('Female n=',nodedata2$e) 
      [6]: paste('Drug A n=', nodedata2$f)
      [7]: paste('Drug B n= ',  nodedata2$g)
      [8]: paste('Refusals n=', nodedata2$h)
      [9]: paste('Drug A n=', nodedata2$i)
      [10]: paste('Drug B n=', nodedata2$j)
      [11]: paste('Refusals n=', nodedata2$k)
      
      ")




```

```

您可以使用-

将其保存为图片
library(rsvg)
library(DiagrammeRsvg)

plot %>% export_svg %>% charToRaw %>% rsvg_png("graph.png")

其中 plotgrViz 图。您还可以在 rsvg_png.

中指定高度和宽度