0

I'm trying to save several plots in R using for loops. Each plot can be obtained from the following lines of code and then I can save the plots individually:

mod_8_heatmap <- make_module_heatmap(module_name = "ME8")

mod_8_heatmap

I tried the following loop to save more plots:

> for (i in 7:10){
+   mod_i_heatmap <- make_module_heatmap(module_name = paste("ME", i, sep = ""))
+   
+   mod_i_heatmap
+   jpeg(paste("ME", i, ".jpeg", sep = ""))
+   mod_i_heatmap
+   dev.off()
+ }

Even though the files are created in the directory, they are blank. I tried this code as well but got the following error:

> for (i in 7:20){
+   mod_i_heatmap <- make_module_heatmap(module_name = paste("ME", i, sep = ""))
+   
+   jpeg(mod_i_heatmap, file=paste("ME", i, ".jpeg", sep = ""))
+   mod_i_heatmap
+   dev.off()
+ }
Error in switch(units, `in` = res, cm = res/2.54, mm = res/25.4, px = 1) *  : 
  non-numeric argument to binary operator

Can you let me know what I'm doing wrong?

Debutant
  • 355
  • 5
  • 17
  • What is `make_module_heatmap`? Is it base graphics, `grid`, or `ggplot2`-based? If not base, you may need to explicitly `print(mod_i_heatmap)` between `jpeg(.)` and `dev.off()`, see https://stackoverflow.com/q/26034177/3358272 – r2evans May 18 '22 at 02:24
  • @r2evans it's a function – Debutant May 18 '22 at 02:34

0 Answers0