talgalili / heatmaply

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

When creating wide plots using Knitr row side colors and dendrogram are too wide #263

Closed mcsimenc closed 3 years ago

mcsimenc commented 3 years ago

I need to make the plot wide so each cell is approximately the shape of a square and I have ~650 columns. First I did heatmaply(x, width = 14000) which didn't seem to have any effect, then I did: heatmaply(x) %>% layout(width = 14000), which reported this:

Specifying width/height in layout() is now deprecated.
Please specify in ggplotly() or plot_ly()

but it did make a wide heatmap in the Knitr HTML output. However the row side colors and dendrogram were stretched out and too wide.

See screenshot of reproducible example

Screenshot from 2021-06-17 13-53-19

library(heatmaply)

datMat = matrix(runif(1000), nrow = 10, ncol = 100)
colnames(datMat) = 1:ncol(datMat)
pal = 1:10
names(pal) = 1:10

# default
heatmaply(datMat, row_side_colors = 1:10,
          row_side_palette = pal)
# too wide
heatmaply(datMat, row_side_colors = 1:10,
          row_side_palette = pal) %>%
  layout(width = 3000)

Thanks! This package is Awesome!

alanocallaghan commented 3 years ago

I think you should check out the arguments subplot_widths and subplot_heights

alanocallaghan commented 3 years ago

Also sorry about the confusing warning, it's a long-running issue see https://github.com/talgalili/heatmaply/issues/86

mcsimenc commented 3 years ago

Thanks, that does it!

heatmaply(datMat, row_side_colors = 1:10,
          row_side_palette = pal,
          subplot_widths = c(0.95, 0.02, 0.03)) %>%
  layout(width = 3000)

Now: Screenshot from 2021-06-17 14-03-04

alanocallaghan commented 3 years ago

Awesome, cheers

nick-youngblut commented 2 years ago

There's still the issue of:

Specifying width/height in layout() is now deprecated. Please specify in ggplotly() or plot_ly()

How can one modify the entire width/height without using layout()?

alanocallaghan commented 2 years ago

The problem is that we use neither ggplotly nor plot_ly to actually generate the final output, rather we use subplot which doesn't take width/height arguments... Should probably raise this on the plotly R github, and maybe I have already; couldn't tell you

nick-youngblut commented 2 years ago

So no one can actually change the size of their plot without using layout(), which is depreciated?

In an Rmarkdown doc, if the height or width is larger than the viewing window, there are no scroll bars to move the viewing window of the plot, so the ends of the heatmap are effectively cut off. This really detracts from the usefulness of heatmaply() if one cannot easily view the entire heatmap

alanocallaghan commented 2 years ago

It's not something that I can really implement as it's a feature of the plotly R library. I'd have to hack at object internals and those are subject to change without notice. I'm going to stick with the public API unless absolutely necessary.

For what it's worth it's been deprecated for like 6 years without being removed so I'm not too concerned.

It's an open issue on the plotly repo eg https://github.com/plotly/plotly.R/issues/1613

nick-youngblut commented 2 years ago

Is there a way to get scroll bars (left-right and up-down) for viewing an entire heatmap in an rmarkdown or quarto doc? If not, then the heatmap can only be so tall; otherwise, the bottom of the heatmap cannot be viewed

alanocallaghan commented 2 years ago

I guess you could wrap it in a div with scrollbars?

https://community.plotly.com/t/how-to-add-vertical-scroll-bar-on-horizontal-bar-chart/12342