rich-iannone / DiagrammeR

Graph and network visualization using tabular data in R
https://rich-iannone.github.io/DiagrammeR/
Other
1.7k stars 246 forks source link

Way to save as pdf? #249

Open ellereve opened 7 years ago

ellereve commented 7 years ago

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.

skanskan commented 7 years ago

Maybe you need to use DiagrammeRsvg

rich-iannone commented 7 years ago

@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
mlagisz commented 5 years ago

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

rich-iannone commented 5 years ago

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

mlagisz commented 5 years ago

@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 commented 5 years ago

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?

nbarrowman commented 5 years ago

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

Johoneyx commented 2 years ago
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?