DiagrammeR icon indicating copy to clipboard operation
DiagrammeR copied to clipboard

DiagrammeR and R Markdown pdf: How to crop the DiagrammeR output to size?

Open SnupSnurre opened this issue 4 years ago • 3 comments

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?

image

SnupSnurre avatar May 04 '20 14:05 SnupSnurre

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:

test-spacing.pdf

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

jsgro avatar Aug 05 '20 03:08 jsgro

Thanks @jsgro! Your height argument works perfectly for me!

fangzhou-xie avatar Jul 12 '21 02:07 fangzhou-xie

Thank you @jsgro, "height" worked to resize my diagram.

yntgmz avatar Jul 23 '21 17:07 yntgmz