DiagrammeR
DiagrammeR copied to clipboard
DiagrammeR and R Markdown pdf: How to crop the DiagrammeR output to size?
Thanks for a great package! I really enjoy writing my diagrams and flowcharts directly in R. However, ever since I started using R Markdown, I have had some bad problems when outputting to pdf.
As you see in the following picture, I managed to make it export the DiagrammeR plot. However, it is not croped to the content and there is a large space below it and the text. I also included fig.align = 'center'
to center it with no effect.
What is going on here?
I am not sure what version you were using, but my circles are larger and there is not such blank space in my output. I am using R 3.6.3 and DiagrammeR_1.0.6.1
- you can use sessionInfo
to output these on your system.
Regarding the diagram, I found that you can change its size by adding a height =
value. Here is your RMD file modified to make it smaller:
---
title: "test2"
date: "8/4/2020"
output:
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document.
```{r}
library(DiagrammeR)
grViz("
digraph box_and_circles {
node [shape = circle]
a; b
a->b
}", height = 200)
```
## Including Plots
You can also embed plots, for example:
By the way I posted elsewhere that in R 4.0.2 there is an error when trying to create a PDF with DiagrammeR
. It is posted here: https://github.com/yihui/tinytex/issues/230
Thanks @jsgro! Your height
argument works perfectly for me!
Thank you @jsgro, "height" worked to resize my diagram.