I have a lot of code to perform some bioinformatics analyis and at some point I need to save some plots. I am using these lines of code:
png(file=paste0(output_dir, name, extension_plot))
plotDendroAndColors(bwnet$dendrograms[[1]], cbind(bwnet$unmergedColors, bwnet$colors),
c("unmerged", "merged"),
dendroLabels = FALSE,
addGuide = TRUE,
hang= 0.03,
guideHang = 0.05)
dev.off()
What happens is: the image is saved white.
I have this problem since months, I can’t create a minimum reproducible example because I don’t understand what causes it. If I debug it it is saved correctly. It does not work when I run the script. Any idea on how even to approach this problem would be really appreciated!
What i want to point out is: it doesn’t depend on the package or the function, sometimes it happens, sometimes not, this forces me to put a browser() after each plot saved like this, and then run the lines one by one before continuing the script. Needless to say this is extremely time consuming and annoying.
Example of sessioninfo where I am sure it happens:
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8
[3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C
[5] LC_TIME=German_Germany.utf8
time zone: Europe/Berlin
tzcode source: internal
attached base packages:
[1] stats4 stats graphics grDevices datasets utils methods base
other attached packages:
[1] DESeq2_1.42.1 SummarizedExperiment_1.32.0
[3] MatrixGenerics_1.14.0 matrixStats_1.3.0
[5] GenomicRanges_1.54.1 GenomeInfoDb_1.38.8
[7] IRanges_2.36.0 S4Vectors_0.40.2
[9] lubridate_1.9.3 forcats_1.0.0
[11] stringr_1.5.1 readr_2.1.5
[13] tibble_3.2.1 tidyverse_2.0.0
[15] GEOquery_2.70.0 Biobase_2.62.0
[17] BiocGenerics_0.48.1 CorLevelPlot_0.99.0
[19] openxlsx_4.2.5.2 readxl_1.4.3
[21] WGCNA_1.72-5 fastcluster_1.2.6
[23] dynamicTreeCut_1.63-1 dplyr_1.1.4
[25] devtools_2.4.5 usethis_2.2.3
[27] tidyr_1.3.1 gridExtra_2.3
[29] ggplot2_3.5.0 Seurat_5.0.3
[31] SeuratObject_5.0.1 sp_2.1-3
[33] purrr_1.0.2