0

I'm trying to run a Rmd file and save all the pictures it contains and for that I'm setting up the document as following:

---
title: "LogR_PCA"
date: "12/14/2021"
output:
  html_document:
    keep_md: yes
---
knitr::opts_chunk$set(dev = "png",
                      dpi = 300,
                      fig.width = 7,
                      echo = FALSE,
                      cache = TRUE)

but when I run code chunks with pictures like this one:



ind.p.2 = fviz_pca_biplot(res_pca, 
                # Individuals
                geom.ind = "point",
                fill.ind = snv_data$clade, col.ind = "black",
                pointshape =21, pointsize = 1.5,
                palette = "jco",
                addEllipses = TRUE,
                # Variables
                alpha.var ="contrib", col.var = "contrib",
                gradient.cols = "Red",
                
                legend.title = list(fill = "Variantes", color = "Contrib",
                                    alpha = "Contrib")
                )
ind.p.2

It doesn't save on the working directory.

Is there anything I need to do?

  • 1
    What package does the `fviz_pca_biplot` function come from? So the image appears in the markdown document but you want to have an extra copy in the working directory? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 28 '22 at 17:32
  • Does this answer your question? [Save all plots already present in the panel of Rstudio](https://stackoverflow.com/questions/35321775/save-all-plots-already-present-in-the-panel-of-rstudio) – Jose Feb 28 '22 at 17:58
  • @MrFlick It comes from the `factoextra` package and yes, the image appears in the markdown output and I'd like to save the image with better DPI. I'm unable to post a reproducible example as 1) the data I'm working is sensitive/private and 2) it would take a lot of code to reproduce the plot I'm showing in the example (even with syntethic data) –  Feb 28 '22 at 18:02
  • @Jose I'm using Rmd and doing as suggested simply saves a png file called "empty" and won't show the rest –  Feb 28 '22 at 18:05
  • 1
    By default markdown HTML documents are compiled to a selfcontained mode so the image is stored in base64 encoded format in the HTML file itself. There is so separate image. You can turn off selfcontained mode so everything is broken up into separate files, or you can just add an additional `ggsave` to your code to save the image wherever you like – MrFlick Feb 28 '22 at 18:06

0 Answers0