plotly / plotly/plotly.R

Unequal facet heights

未关闭
#2,100 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

In the reprex below, the first and last panels are noticeably taller than the others (note the y axis ticks are overlapping for the remaining panels).

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(plyr)
#> 
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:plotly':
#> 
#>     arrange, mutate, rename, summarise

date <- rep(as.Date(1:365,origin='2011-1-1'),7)
location <- factor(rep(1:7,365))
product <- rep(letters[1:7], each=365)
value <- c(sample(1:10, size=365, replace=T),
           sample(1:3, size=365, replace=T),
           sample(10:100, size=365, replace=T), 
           sample(1:50, size=365, replace=T),
           sample(1:20, size=365, replace=T),
           sample(50:100, size=365, replace=T),
           sample(1:100, size=365, replace=T))
dat<-data.frame(date,location,product,value)

p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
    geom_line()+
  theme(panel.spacing.y = ggplot2::unit(1, "lines")) +
  facet_grid(product ~ ., scales = "fixed")

ggplotly(p)

(Also, the legend compresses the first few panels awkwardly, but that is a separate issue).

The problem also occurs with facet_wrap():

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(plyr)
#> 
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:plotly':
#> 
#>     arrange, mutate, rename, summarise

date <- rep(as.Date(1:365,origin='2011-1-1'),7)
location <- factor(rep(1:7,365))
product <- rep(letters[1:7], each=365)
value <- c(sample(1:10, size=365, replace=T),
           sample(1:3, size=365, replace=T),
           sample(10:100, size=365, replace=T), 
           sample(1:50, size=365, replace=T),
           sample(1:20, size=365, replace=T),
           sample(50:100, size=365, replace=T),
           sample(1:100, size=365, replace=T))
dat<-data.frame(date,location,product,value)

p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
    geom_line()+
  theme(panel.spacing.y = ggplot2::unit(1, "lines")) +
  facet_wrap(ncol = 1, vars(product), scales = "fixed")

ggplotly(p)

This issue doesn't appear to be coming from ggplot, but rather from ggplotly:

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(plyr)
#> 
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:plotly':
#> 
#>     arrange, mutate, rename, summarise

date <- rep(as.Date(1:365,origin='2011-1-1'),7)
location <- factor(rep(1:7,365))
product <- rep(letters[1:7], each=365)
value <- c(sample(1:10, size=365, replace=T),
           sample(1:3, size=365, replace=T),
           sample(10:100, size=365, replace=T), 
           sample(1:50, size=365, replace=T),
           sample(1:20, size=365, replace=T),
           sample(50:100, size=365, replace=T),
           sample(1:100, size=365, replace=T))
dat<-data.frame(date,location,product,value)

p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
    geom_line()+
  theme(panel.spacing.y = ggplot2::unit(1, "lines")) +
  facet_grid(product ~., scales = "fixed")

print(p)

Created on 2022-01-12 by the reprex package (v2.0.1)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 ggplotly() 运行提供的 R reprex,然后将 facet_grid() 和 facet_wrap() 的输出与尺寸正确的 ggplot 结果进行比较。跟踪 ggplotly 对 facet 布局的转换,并确定面板高度或间距在哪一处变得不均等。完成的标准是两个示例都能渲染出高度相等的面板,且 y 轴刻度不会重叠。

由索引模型根据 Issue 内容生成。

评估

技术栈
plotly, r
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。