Closed nlhuong closed 7 years ago
The intention of plot_method
is to choose which library produces the plots. plot_method="ggplot"
simply uses ggplot to create plot objects, which are internally converted into plotly objects using plotly::ggplotly()
.
If you wish to examine the ggplot objects which are turned into an interactive heatmap you could use return_ppxpy=TRUE
(this also works with plot_method="plotly"
to return plotly objects. If you wanted to plot them you could do something like this:
library(ggplot2)
library(heatmaply)
library(grid)
library(gridExtra)
plots <- heatmaply(mtcars, plot_method = "ggplot", return_ppxpy=TRUE)
## ggplot objects
sapply(plots, class)
## Remove non-existent plots
plots <- plots[!sapply(plots, is.null)]
## Convert to grobs (grid objects)
plots <- lapply(plots, ggplotGrob)
## Set widths and heights to be the same
plots$p$widths <- plots$px$widths <- plots$py$widths <- unit.pmax(
plots$p$widths,
plots$px$widths,
plots$py$widths)
plots$p$heights <- plots$px$heights <- plots$py$heights <- unit.pmax(
plots$p$heights,
plots$px$heights,
plots$py$heights)
## Plot them
grid.arrange(plots$py, textGrob(""), plots$p, plots$px, nrow=2)
It is beyond the current scope of this package to plot dendrogram heatmaps with gridExtra. It would be impossible to produce dendrogram heatmaps with just ggplot2 as the dendrogram and heatmap plots are separate ggplot objects, and they have to be combined with grid.arrange. If you would really like this feature we could consider it for inclusion in future versions.
Thank you! This explains my issue.
Is there a better way to use heatmaply and obtain a plot (without using the plotly
? The result that you provided @Alanocallaghan doesn't create a nice plot:
You're going to have to be more specific in what you actually want here
I am trying to obtain the same plot both in a interactive and non interactive version.
heatmaply(mtcars)
produces a interactive version.
I would like to have exactly the same looking plot but as a png so I can have reported in a pdf document. I know a workaround would be using webshot
of the plotly output. But I wonder if there's a cleaner way, the explanation that you provided, reported a weird looking plot (the one from the image).
Thank you for your quick response btw.
If you want exactly the same plot, then using plotly::export
is the easiest way. If you want something vaguely similar, ggheatmap
is a better option.
library(heatmaply)
ggheatmap(mtcars)
Thanks a lot!
I installed heatmaply and ggplot2 with devtools::install_github. However, heatmaply does not generate ggplot object even when plot_method = "ggplot" is given as an argument.
Here are the commands and the sessionInfo():
[1] "plotly" "htmlwidget"
sessionInfo()
R version 3.4.0 (2017-04-21) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.6
Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] parallel stats4 stats graphics grDevices utils datasets methods base
other attached packages: [1] heatmaply_0.10.1 viridis_0.4.0 viridisLite_0.2.0
[4] plotly_4.7.1 ggplot2_2.2.1.9000 edgeR_3.18.1
[7] limma_3.32.2 DESeq2_1.16.1 SummarizedExperiment_1.6.3 [10] DelayedArray_0.2.7 matrixStats_0.52.2 Biobase_2.36.2
[13] GenomicRanges_1.28.3 GenomeInfoDb_1.12.2 IRanges_2.10.2
[16] S4Vectors_0.14.3 BiocGenerics_0.22.0
loaded via a namespace (and not attached): [1] bitops_1.0-6 bit64_0.9-7 RColorBrewer_1.1-2 httr_1.2.1
[5] prabclus_2.2-6 tools_3.4.0 backports_1.1.0 R6_2.2.2
[9] KernSmooth_2.23-15 rpart_4.1-11 Hmisc_4.0-3 DBI_0.7
[13] lazyeval_0.2.0 colorspace_1.3-2 trimcluster_0.1-2 nnet_7.3-12
[17] gridExtra_2.2.1 bit_1.1-12 compiler_3.4.0 htmlTable_1.9
[21] TSP_1.1-5 labeling_0.3 caTools_1.17.1 diptest_0.75-7
[25] scales_0.5.0.9000 checkmate_1.8.2 DEoptimR_1.0-8 mvtnorm_1.0-6
[29] robustbase_0.92-7 genefilter_1.58.1 stringr_1.2.0 digest_0.6.12
[33] foreign_0.8-67 XVector_0.16.0 base64enc_0.1-3 pkgconfig_2.0.1
[37] htmltools_0.3.6 htmlwidgets_0.9 rlang_0.1.2 RSQLite_2.0
[41] shiny_1.0.3 bindr_0.1 jsonlite_1.5 crosstalk_1.0.0
[45] gtools_3.5.0 mclust_5.3 BiocParallel_1.10.1 acepack_1.4.1
[49] dendextend_1.5.2 dplyr_0.7.2 RCurl_1.95-4.8 magrittr_1.5
[53] modeltools_0.2-21 GenomeInfoDbData_0.99.0 Formula_1.2-1 Matrix_1.2-9
[57] Rcpp_0.12.12 munsell_0.4.3 yaml_2.1.14 stringi_1.1.5
[61] whisker_0.3-2 MASS_7.3-47 zlibbioc_1.22.0 gplots_3.0.1
[65] flexmix_2.3-14 plyr_1.8.4 grid_3.4.0 blob_1.1.0
[69] gdata_2.18.0 lattice_0.20-35 splines_3.4.0 annotate_1.54.0
[73] locfit_1.5-9.1 knitr_1.17 fpc_2.1-10 reshape2_1.4.2
[77] codetools_0.2-15 geneplotter_1.54.0 XML_3.98-1.9 glue_1.1.1
[81] gclus_1.3.1 latticeExtra_0.6-28 data.table_1.10.4 httpuv_1.3.3
[85] foreach_1.4.3 gtable_0.2.0 purrr_0.2.3 tidyr_0.7.0
[89] kernlab_0.9-25 assertthat_0.2.0 mime_0.5 xtable_1.8-2
[93] class_7.3-14 survival_2.41-3 seriation_1.2-2 tibble_1.3.4
[97] iterators_1.0.8 registry_0.3 AnnotationDbi_1.38.1 memoise_1.1.0
[101] bindrcpp_0.2 cluster_2.0.6