6

I'm using mermaid diagrams in my Rmd reports compiled with Rstudio. In the HTML/PDF output, there is a lot of blank space above and below the charts, see example below.

# Header
Text
```{r}
library(DiagrammeR)
mermaid("
graph TD
    classDef style_main_node fill:orange,stroke:#333,stroke-width:0px;
    classDef style_sub_node fill:lightgray,stroke:#333,stroke-width:0px;

0(Top)
0 --> A1(Left)
0 --> B1(Center)
0 --> C1(Right)

    class 0 style_main_node;
    class A1,B1,C1 style_sub_node;
")
```
Text

HTML Output: rendered Rmd with mermaid graph

Is there a way to crop off/adjust the white space around the graph? And possibly also to change its size?

mavericks
  • 478
  • 6
  • 18

1 Answers1

2

Just specify height and width around diagram with: height = '100%', width = '100%'

# Header
Text
```{r}
library(DiagrammeR)
mermaid("
graph TD
    classDef style_main_node fill:orange,stroke:#333,stroke-width:0px;
    classDef style_sub_node fill:lightgray,stroke:#333,stroke-width:0px;

0(Top)
0 --> A1(Left)
0 --> B1(Center)
0 --> C1(Right)

    class 0 style_main_node;
    class A1,B1,C1 style_sub_node;
", height = '100%', width = '100%')
```
Text

enter image description here

Abhishek Gurjar
  • 7,152
  • 9
  • 35
  • 40
Radovan Miletić
  • 1,581
  • 3
  • 10