8

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?

1 Answer 1

3

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

1
  • Thanks so much @RadovanMiletić – very simple and elegant solution!
    – mavericks
    Jan 9, 2020 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.