plotly / plotly/plotly.R

subplot does not seem to handle well relatively long lists

Open
#1,515 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plotly.js
Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm trying to use subplot in order to vertically group bar plots, sharing their x-axis.

Here are example data which have 28 groups where I'm creating a bar plot over 4 families in each and then trying to vertically combine them using subplot:

set.seed(1)
df <- data.frame(group = paste0("G",unlist(lapply(1:28,function(i) rep(i,4)))),
                 family = paste0("F",rep(1:4,28)),
                 log2n = log2(as.integer(runif(4*28,0,30))+1),
                 stringsAsFactors = F)

Creating the list of bar plots:

library(plotly)
groups <- unique(df$group)
y.range <- c(0,max(df$log2n))
plot.list <- lapply(1:length(groups),function(g){
  group.df <- dplyr::filter(df,group == groups[g])
  plot_ly(x=group.df$family,y=group.df$log2n,type='bar',name=group.df$family,color=group.df$family,showlegend=(g==length(groups))) %>%
    layout(yaxis=list(range=y.range))
})

If I try:
p <- plotly::subplot(plot.list,shareX=T,nrows=length(plot.list))

Screen Shot 2019-04-10 at 6 48 53 PM

So it seems like some sort of an overflow.

I gradually cut down on the number of plots in plot.list that I run subplot on and when reach 19 it seemed to stop 'overflowing':
p <- plotly::subplot(plot.list[1:19],shareX=T,nrows=19)
Screen Shot 2019-04-10 at 6 50 37 PM

Any idea if there's hope to get all 28 bar plots without overflowing?

Thanks a lot

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible call to plotly::subplot using 28 vertically stacked bar plots, then compare it with the 19-plot case that does not overflow. Investigate how subplot handles nrows and shared x-axes for long plot lists; done means all 28 plots render without overflow while preserving the shared axis and legend.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.