plotly / plotly/plotly.R

`add_annotations` incompatible with multicategory axis

Open
#1,838 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

I've been attempting to plot horizontal arrows using add_annotations in a plotly object with a multicategory y-axis. Instead of positioning annotations along the y-axis, they are all positioned at the origin.

(Because the same behavior occurs with other types of annotation, I have included some text in the reprex as well.)

library(tibble)
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

tribble(
  ~cat1, ~cat2, ~start, ~end,
  "a", "f", 1, 2,
  "a", "g", 2, 3,
  "a", "h", 3, 0,
  "b", "f", 0, 3
  ) %>% 
  plot_ly(y = ~list(cat1, cat2)) %>% 
  add_markers(x = ~start) %>% 
  add_markers(x = ~end) %>% 
  add_annotations(text = ":(",
                  showarrow = TRUE,
                  xref = "x", axref = "x",
                  yref = "y", ayref = "y",
                  x = ~start,
                  ax = ~end,
                  y = ~list(cat1, cat2),
                  ay = ~list(cat1, cat2))

plot

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 supplied R reprex and the add_annotations entry point, then trace how multicategory y-axis values are handled for annotations versus markers. Reproduce the origin positioning with the example and verify that annotations using list(cat1, cat2) are positioned along the multicategory axis without regressing other annotation types.

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.