Created
June 14, 2020 09:15
-
-
Save mathzero/a2070a24a6b418740c44a5c023f5c01e to your computer and use it in GitHub Desktop.
Save pheatmap function (png or pdf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### slightly adapted from here to save png or pdf and specify resolution etc: https://stackoverflow.com/questions/43051525/how-to-draw-pheatmap-plot-to-screen-and-also-save-to-file | |
# function detects '.png' or '.pdf' in the declared filename and assigns that file type | |
### pheatmap save function | |
save_pheatmap <- function(x, filename, width=12, height=12){ | |
stopifnot(!missing(x)) | |
stopifnot(!missing(filename)) | |
if(grepl(".png",filename)){ | |
png(filename, width=width, height=height, units = "in", res=300) | |
grid::grid.newpage() | |
grid::grid.draw(x$gtable) | |
dev.off() | |
} | |
else if(grepl(".pdf",filename)){ | |
pdf(filename, width=width, height=height) | |
grid::grid.newpage() | |
grid::grid.draw(x$gtable) | |
dev.off() | |
} | |
else{ | |
print("Filename did not contain '.png' or '.pdf'") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment