plotly / plotly/plotly.R

Markers are not alligned with bars when a double horizontal axis is used

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

还没有人认领这个 Issue。

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

描述

Plotly behaves strangely when two sets of data are superimposed, and there is a double horizontal axis.
Bars overlayed on bars give no issue: see the following reprex.

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

plot_ly() %>%
  add_trace(x = ~1:31,
            y = ~1:31,
            name = 'blue data',
            type = 'bar') %>% 
  add_trace(x = ~101:131,
            y = ~31:1,
            opacity = 0.7,
            name = 'orange data',
            type = 'bar',
            xaxis = 'x2') %>% 
  layout(xaxis = list(title = ''),
         xaxis2 = list(
           overlaying = "x",                                        
           side = "top")
  )
#> Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
#> Please use `arrange()` instead.
#> See vignette('programming') for more help
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.

image

Created on 2020-10-29 by the reprex package (v0.3.0)

Now look at what happens if I replace the orange bars with orange markers: the second x axis on the top is squeezed between the second and the second to last bar, messing up the visualization.

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

plot_ly() %>%
  add_trace(x = ~1:31,
            y = ~1:31,
            name = 'blue data',
            type = 'bar') %>% 
  add_trace(x = ~101:131,
            y = ~31:1,
            opacity = 0.7,
            name = 'orange data',
            type = 'scatter',
            mode = 'markers',
            xaxis = 'x2') %>% 
  layout(xaxis = list(title = ''),
         xaxis2 = list(
           overlaying = "x",                                        
           side = "top")
  )
#> Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
#> Please use `arrange()` instead.
#> See vignette('programming') for more help
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.

image

Created on 2020-10-29 by the reprex package (v0.3.0)

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先运行使用 add_trace() 和 layout() 的两个 plot_ly() 示例,比较条形图和标记的情况。跟踪 R 绘图入口如何处理叠加的 xaxis 和 xaxis2 配置;当标记使用与条形图相同的水平对齐方式且不会挤压顶部坐标轴时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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