plotly / plotly/plotly.R

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

Open
#1,875 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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)

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 by running the two plot_ly() examples with add_trace() and layout(), comparing the bar and marker cases. Trace how the R plotting entry points handle overlaid xaxis and xaxis2 configurations; done means markers use the same horizontal alignment as bars without squeezing the top axis.

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.