Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble saving plots under format other than html #90

Open
paulegre opened this issue Mar 18, 2017 · 8 comments
Open

Trouble saving plots under format other than html #90

paulegre opened this issue Mar 18, 2017 · 8 comments

Comments

@paulegre
Copy link

Data.tree allows you to generate plots for trees very easily with the "plot" command. However, saving the resulting image in formats such as png, pdf, or jpeg fails (even using Rstudio). The issue was mentioned already on the web ( http://stackoverflow.com/questions/42108105/in-r-how-do-i-save-a-data-tree-plot-to-a-file) but the answers provided there did not work for me, so I have used screenshots for the time being. I will continue to look into the documentation from the inbuilt packages used by data.tree, but it would be nice eventually if some additional piece of code can be extracted for users of data.tree like me who appreciate the self-contained aspect of the package.

@sebastian-c
Copy link

The code there doesn't work with newer versions of data.tree (The grViz(ToGraphViz()) process has changed). This does work:

data(acme)
treeAsSVG <- export_svg(render_graph(ToDiagrammeRGraph(acme)))
writeLines(treeAsSVG, "filename.svg")

@gluc
Copy link
Owner

gluc commented Mar 24, 2017

Thx, Sebastian.

A similar way is this:

Pre-requisite: DiagrmmeRsvg and dependencies need to be installed

Depending on your OS, you might have to install V8. For example on ubuntu:

sudo apt-get install libv8-3.14-delibv8-3.14-dev
install.packages("DiagrammeRsvg")

On my Windows system, I didn't have to install anything (maybe because Chrome is installed)?

Once DiagrammeRsvg is available, run:

library(data.tree)
data(acme)
library(DiagrammeR)
export_graph(ToDiagrammeRGraph(acme), "export.pdf")

@paulegre
Copy link
Author

Thank you Sebastian and Christoph. I am still stuck, though, probably on the step described by Christoph. When I execute the code, even with DiagramRsvg installed, I get an error message:
"Error in loadNamespace(name) : there is no package called ‘rsvg’". I am using OS El Capitan 10.11.6 but no idea if that's relevant.

@gluc
Copy link
Owner

gluc commented Mar 25, 2017

Are you sure DiagrammeRsvg installed without errors? Can you check if the r package is installed? My guess is that v8 is not installed. Here's a link, though I couldn't try it out myself: http://macappstore.org/v8/
If that doesn't help, could you please send me the output of sessionInfo()

@gluc gluc reopened this Mar 25, 2017
@paulegre
Copy link
Author

Thanks Christoph. I could install v8 following the link you sent. But the problem persists. I will send you the output of my session, just based on trying to execute the code you sent on the acme data. Many thanks again.

@vnijs
Copy link

vnijs commented Mar 25, 2017

@paulegre This is likely due to an install issue with rsvg. On Mac you will need to install librsvg. See comments on jeroen's github page linked below

https://github.com/jeroen/rsvg

@paulegre
Copy link
Author

paulegre commented Mar 25, 2017

Thanks much. Following your advice I installed librsvg from my Terminal, following instructions found at: http://macappstore.org/librsvg/
but that does not seem to fix the problem even after restarting my Mac. So the problem may come from my version of R, as asked by Christoph. I will try to update it and will keep you all posted. Thank you so much for your support.

@NataGH
Copy link

NataGH commented Mar 27, 2017

Hi Cristoph,
following your instructions:

library(data.tree)
data(acme)
library(DiagrammeR)
export_graph(ToDiagrammeRGraph(acme), "export.pdf")

I was wondering if there is a way to add a title and legend to the exported pdf file.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants