talgalili / heatmaply

Interactive Heat Maps for R Using plotly
380 stars 73 forks source link

subplot_width/subplot_height not functioning #63

Closed anniepyim closed 7 years ago

anniepyim commented 7 years ago

Is it possible to adjust the width/height of the dendrogram on the left and the top? Is subplot_widths for that purpose? I cannot get that working though...

alanocallaghan commented 7 years ago

Can you post an example please?

anniepyim commented 7 years ago

screen shot 2017-05-05 at 2 02 20 pm

Let's say I want to reduce the width of dendrogram on the right, and the height of the dendrogram at the top, so I could have a larger heatmap. How could I achieve this?

heatmaply(subsetdata,scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", high = "red", midpoint = 0)) %>% layout(margin = list(l = 50, b = 80),xaxis=list(tickfont=list(size=7),tickangle=270),yaxis2=list(tickfont=list(size=5)))

alanocallaghan commented 7 years ago

This seems to be two related bugs, for the time being the code below should accomplish what you need (providing you tweak the subplot_widths/subplot_heights values)

heatmaply(
    mtcars,
    scale="column",
    subplot_widths=c(0.5, 0.5),
    subplot_heights=c(0.5, 0.5),
    plot_method="plotly",
    col = RdBu) %>% 
layout(
    margin = list(l = 50, b = 80),
    xaxis = list(
        tickfont=list(size=7),
        tickangle=270),
    yaxis2=list(tickfont=list(size=5)))
alanocallaghan commented 7 years ago

This is not the desired behaviour... Using plot_method="ggplot", this functionality is broken (only for widths, heights function as expected).

EDIT: This seems to be a ggplotly bug...

screenshot from 2017-05-05 14-21-47

alanocallaghan commented 7 years ago

Sorry @anniepyim you will need to install from this github repo rather than CRAN, ie devtools::install_github("talgalili/heatmaply")

talgalili commented 7 years ago

Hi @Alanocallaghan I think there is some bug in the right-side dendrogram that was somehow introduced by a recent version of ggplot2 on github. Could you verify this on your end?

alanocallaghan commented 7 years ago

It happens for me on ggplot2 v2.2.1.9000 and plotly 4.6.0, but not on ggplot2 v4.5.6 and v2.2.1. The issue is in converting from a ggplot object using ggplotly, so it might be a bug in ggplotly or a ggplot2 interface change.

alanocallaghan commented 7 years ago

I would note that it was fine until I updated ggplot2, so that is the more likely culprit

talgalili commented 7 years ago

ok. Using your code from above I get:

heatmaply(
    mtcars,
    scale="column",
    subplot_widths=c(0.5, 0.5),
    subplot_heights=c(0.5, 0.5),
    plot_method="plotly",
    col = RdBu) %>% 
layout(
    margin = list(l = 50, b = 80),
    xaxis = list(
        tickfont=list(size=7),
        tickangle=270),
    yaxis2=list(tickfont=list(size=5)))

image

And using it with the default plot_method now also works fine:

heatmaply(
  mtcars,
  scale="column",
  subplot_widths=c(0.5, 0.5),
  subplot_heights=c(0.5, 0.5),
  # plot_method="plotly", # i.e. ggplot
  col = RdBu) %>% 
  layout(
    margin = list(l = 50, b = 80),
    xaxis = list(
      tickfont=list(size=7),
      tickangle=270),
    yaxis2=list(tickfont=list(size=5)))

image

talgalili commented 7 years ago

@Alanocallaghan thanks for solving this. I've now closed the issue and added a note that this was done to the various docs in the package (NEWS/.Rd/DESCRIPTION).

@anniepyim please see the following simple example for using the fixed parameters:

heatmaply(percentize(mtcars),
  subplot_widths=c(0.6, 0.4),
  subplot_heights=c(0.05, 0.95))

Which produces:

image

anniepyim commented 7 years ago

@talgalili It looks like I have to put "plot_method="plotly"" to make that works?

heatmaply(percentize(mtcars),
   scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", high = "red", midpoint = 0.5),
   subplot_widths=c(0.6, 0.4),
   subplot_heights=c(0.05, 0.95))

Because without that I am getting something like this, where the dendrogram on the right is gone (it is actually there, but the orientation is wrong):

screen shot 2017-05-08 at 1 57 53 pm

But with the "plot_method="plotly"", I wouldn't be able to customize the colour like I could before:

heatmaply(percentize(mtcars),
   scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", high = "red", midpoint = 0.5),
   plot_method="plotly",
   subplot_widths=c(0.6, 0.4),
   subplot_heights=c(0.05, 0.95))

screen shot 2017-05-08 at 1 57 09 pm

Are there any ways to work around this? Thanks a lot!

talgalili commented 7 years ago

Hi. What is your sessionInfo() ?

anniepyim commented 7 years ago

R version 3.3.1 (2016-06-21) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.6 (El Capitan)

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] stats graphics grDevices utils datasets methods base

other attached packages: [1] heatmaply_0.9.2 viridis_0.4.0 viridisLite_0.2.0 plotly_4.6.0.9000 [5] ggplot2_2.2.1.9000

loaded via a namespace (and not attached): [1] gtools_3.5.0 modeltools_0.2-21 purrr_0.2.2 kernlab_0.9-25
[5] reshape2_1.4.2 lattice_0.20-34 colorspace_1.3-2 htmltools_0.3.6
[9] stats4_3.3.1 yaml_2.1.14 DBI_0.6 prabclus_2.2-6
[13] RColorBrewer_1.1-2 registry_0.3 fpc_2.1-10 foreach_1.4.3
[17] plyr_1.8.4 robustbase_0.92-7 stringr_1.2.0 munsell_0.4.3
[21] gtable_0.2.0 htmlwidgets_0.8 caTools_1.17.1 mvtnorm_1.0-6
[25] codetools_0.2-15 labeling_0.3 httpuv_1.3.3 crosstalk_1.0.0
[29] seriation_1.2-1 flexmix_2.3-13 class_7.3-14 DEoptimR_1.0-8
[33] trimcluster_0.1-2 Rcpp_0.12.10 xtable_1.8-2 KernSmooth_2.23-15 [37] scales_0.4.1 diptest_0.75-7 gdata_2.17.0 jsonlite_1.4
[41] mime_0.5 gplots_3.0.1 gridExtra_2.2.1 digest_0.6.12
[45] stringi_1.1.5 gclus_1.3.1 shiny_1.0.0 dplyr_0.5.0
[49] grid_3.3.1 tools_3.3.1 bitops_1.0-6 magrittr_1.5
[53] lazyeval_0.2.0 tibble_1.3.0 cluster_2.0.5 whisker_0.3-2
[57] tidyr_0.6.2 dendextend_1.5.2 MASS_7.3-45 assertthat_0.2.0
[61] httr_1.2.1 iterators_1.0.8 R6_2.2.0 TSP_1.1-5
[65] mclust_5.2.2 nnet_7.3-12

alanocallaghan commented 7 years ago

@anniepyim you can use the col argument to specify colours when using plot_method = "plotly". This would be done by supplying a vector of colours:

heatmaply(percentize(mtcars),
   col = colorRampPalette(c("blue", "white", "red"))(255),
   plot_method="plotly",
   subplot_widths=c(0.6, 0.4),
   subplot_heights=c(0.05, 0.95))

Or by specifying a palette function:

heatmaply(percentize(mtcars),
   col = colorRampPalette(c("blue", "white", "red")),
   plot_method="plotly",
   subplot_widths=c(0.6, 0.4),
   subplot_heights=c(0.05, 0.95))
talgalili commented 7 years ago

@anniepyim I think the dendrogram orientation problem is a new issue introduced by ggplot2. Download ggplot2 from CRAN and it should work. In the next week or two we'll get to look into this ggplot2 bug and report it (once we understand if it is a ggplot2 or plotly issue - but I've noticed it works fine when using the CRAN version of ggplot2).