plotly / plotly/plotly.R

Annotations for factor in barplot misplaced

Open
#2,211 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

When adding annotations to a barplot with x as factor, the plot gets squished
Problem arises since R plotly version 4.10.1. Worked fine until plotly 4.9.2.1

This works not

plotData <- data.frame(x = factor(1991:2000), y = rnorm(10))
plot_ly(data = plotData, x = ~x, y = ~y, type = "bar") %>%
  layout(annotations = list(x = plotData$x, y = 0, text = 1:10))

Screenshot from 2022-12-02 17-14-44

This works, although it is safer to match on the actual x-values (factor levels) rather than on a numeric variant (mind the -1 to get it start at 0!)

plotData <- data.frame(x = factor(1991:2000), y = rnorm(10))
plot_ly(data = plotData, x = ~x, y = ~y, type = "bar") %>%
  layout(annotations = list(x = as.numeric(plotData$x) - 1, y = 0, text = 1:10))

Screenshot from 2022-12-02 17-15-09

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 provided plot_ly() and layout(annotations = ...) reproduction using factor x values, comparing the behavior between plotly.R 4.9.2.1 and 4.10.1. Trace how factor annotations are converted and verify that annotations remain aligned with the bar categories without requiring numeric factor values.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.