Closed jorgesinval closed 2 years ago
This seems to be significantly trickier than it ought to be, but I'm looking into it.
Excellent!
On Tue, Jan 8, 2019 at 4:33 PM Alex Lishinski notifications@github.com wrote:
This seems to be significantly trickier than it ought to be, but I'm looking into it.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alishinski/lavaanPlot/issues/12#issuecomment-452363743, or mute the thread https://github.com/notifications/unsubscribe-auth/AH5QNx-kdVzfUMr-ZvViF9V8TgbDKa0Lks5vBMhdgaJpZM4WOoAp .
The way that I've dealt with this in the past is simply to export the plot as an image and then include that in the rmarkdown document that I'm going to render to a pdf, but I'd like to avoid that step if possible. It kind of seems like it might be an inherent diagrammeR issue though: https://github.com/rich-iannone/DiagrammeR/issues/133
I am just in general unable to save figures except for manually click Export in RStudio. The documentation does not seem to have anything on this. How does one save figures programmatically?
I've come across the same problem. Has anyone been able to programmatically save the plots?
Seems like this is solved by adding always_allow_html: yes
in the yaml
header!
Yes, I met the same problem. How to save the plot to a pdf file?
One possible workaround.
tempDir <- tempfile()
dir.create(tempDir)
htmlFile <- file.path(tempDir, "lavaan_model.html")
htmltools::save_html(lavaan_model,htmlFile)
# webshot supports other formats as well (png, bmp etc.)
# This will create lavaan_model.pdf in the working directory
webshot::webshot(htmlFile,"lavaan_model.pdf")
Yes, and you can also use pagedown::chrome_print()
. But if you only want to directly plot a diagram it is not straightforward.
That's true. Probably in the meantime, we could have a function that does all this work in the background. But we'll still only get screenshots and not diagrams.
I wrote 2 new functions and put them in a new branch called export_functions:
save_png
will save your plot as a .png programmatically
embed_plot_pdf
you can use in an .Rmarkdown document that you knit into a pdf to embed your plot
Give those a try and let me know what you think
And whether they work, of course
It is working. Both the svg function and the pdf one:
So... we always need to create a separate pdf (with only the plot) to then be added to the Rmarkdown one, right?
Yeah the embed_plot_pdf
function converts and saves the plot as a pdf (So you should use a .pdf file name) in your working directory and then uses knitr::include_graphics
to put the plot into the knitted (knitr-ed?) .pdf. I haven't figured out how to do it without saving, but please let me know if you have any suggestions.
I wonder where the 'export_functions' is now, you know, the link does not work. @alishinski
Is it possible to knit the diagrams on a PDF?