DiagrammeR icon indicating copy to clipboard operation
DiagrammeR copied to clipboard

Way to save as pdf?

Open ellereve opened this issue 6 years ago • 8 comments

I want to use DiagrammeR in slides but for various reasons the slides need to be done in knitr, not markdown. Is there any way to save the images as pdfs? Using the R export allows for png/jpg/bmp, but then I have resizing issues and using pdf('') dev.off() doesn't work.

ellereve avatar Oct 09 '17 14:10 ellereve

Maybe you need to use DiagrammeRsvg

skanskan avatar Oct 15 '17 14:10 skanskan

@ellereve Sorry for the delay on this. This code definitely works to make a .pdf from a graph object:

library(DiagrammeR)

graph <-
  create_graph() %>%
  add_global_graph_attrs(
    attr = "outputorder",
    value = "edgesfirst",
    attr_type = "graph") %>%
  add_full_graph(
    n = 5,
    node_aes = node_aes(
      style = "solid",
      color = "darkgreen"),
    edge_aes = edge_aes(
      headclip = FALSE,
      tailclip = FALSE,
      arrowhead = "none",
      color = "orange")) %>%
  set_node_attr_to_display(
    attr = NULL)

graph %>% export_graph(file_name = "my_crazy_graph.pdf")

The file looks like this:

screen_shot_of_pdf

rich-iannone avatar Nov 11 '17 07:11 rich-iannone

getting ":1919791: Invalid asm.js: Function definition doesn't match use" - any suggestions how to make this work?

mlagisz avatar Mar 14 '19 00:03 mlagisz

@mlagisz Could you provide the code that resulted in the error?

rich-iannone avatar Mar 14 '19 00:03 rich-iannone

@mlagisz Could you provide the code that resulted in the error?

hi, thanks for the quick response. I run exactly the code you provided above as an example (I also tried on my own graph with the same outcome) my sessionInfo():

sessionInfo() R version 3.5.1 (2018-07-02) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.6

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale: [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] DiagrammeRsvg_0.1 rsvg_1.3 readxl_1.1.0 DiagrammeR_1.0.0 forcats_0.3.0
[6] stringr_1.3.1 dplyr_0.8.0.1 purrr_0.2.5 readr_1.1.1 tidyr_0.8.1
[11] tibble_2.0.1 ggplot2_3.0.0 tidyverse_1.2.1

Hope that helps and you will be able to point me to a solution.

It is a great package, but I really need to get the graph into pdf - the bitmaps are too low resolution and cannot be edited. Thank you!

mlagisz avatar Mar 14 '19 01:03 mlagisz

Sorry, actually the function did export the graph, just the message was unusual. The issue is resolved, but I have some other questions: Is there a way to define the layout of the graph to be used - currently only one fixed way of node placement is used, while when I use render_graph I can specify one of the fw=ew layouts, but also every time it gets rendered the nodes are placed differently within the same layout type, so its non-replicable. Why is that and is there a way around?

mlagisz avatar Mar 14 '19 11:03 mlagisz

I reported the same message here: https://github.com/rich-iannone/DiagrammeRsvg/issues/7

nbarrowman avatar Mar 20 '19 17:03 nbarrowman

graph %>% export_graph(file_name = "my_crazy_graph.pdf")

Sorry, actually the function did export the graph, just the message was unusual. The issue is resolved, but I have some other questions: Is there a way to define the layout of the graph to be used - currently only one fixed way of node placement is used, while when I use render_graph I can specify one of the fw=ew layouts, but also every time it gets rendered the nodes are placed differently within the same layout type, so its non-replicable. Why is that and is there a way around?

Hi, Have you found a solution for this? Is there any way to save the graph as pdf with a certain layout?

Johoneyx avatar Mar 21 '22 17:03 Johoneyx