Annotations for factor in barplot misplaced
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))

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))

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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