category axis and shapes not playing well when data representing numbers and xref = "x"
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Providing a list of strings representing numbers for category axis converts them to number rather than keeping them as strings.
This for me results in the inability to use shapes to shade part of the graph.
Example of what is not working:
library(plotly)
# Sample data
x <- c("1234", "2345", "3456", "4567")
y <- c(10, 15, 8, 12)
# Create a Plotly chart with a bar plot
fig <- plot_ly(x = ~x, y = ~y)
# Define a rectangle shape
shapes <- list(
list(
type = "rect",
line = list(color = "red"),
x0 = "1234", x1 = "2345",
y0 = 0, y1 = 1,
xref = "x",
yref = "paper"
)
)
# Add the rectangle shape to the layout
fig <- fig %>% layout(
title = 'Highlighting with Lines',
xaxis = list(
type = 'category',
autotypenumbers = 'strict'
),
shapes = shapes
)
# Display the chart
fig
Example of what is working:
library(plotly)
# Sample data
x <- c("#1234", "#2345", "#3456", "#4567")
y <- c(10, 15, 8, 12)
# Create a Plotly chart with a bar plot
fig <- plot_ly(x = ~x, y = ~y)
# Define a rectangle shape
shapes <- list(
list(
type = "rect",
line = list(color = "red"),
x0 = "#1234", x1 = "#2345",
y0 = 0, y1 = 1,
xref = "x",
yref = "paper"
)
)
# Add the rectangle shape to the layout
fig <- fig %>% layout(
title = 'Highlighting with Lines',
xaxis = list(
type = 'category',
autotypenumbers = 'strict'
),
shapes = shapes
)
# Display the chart
fig
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 by running the supplied R reproduction with plot_ly() and layout(), comparing numeric-looking category labels with the working labels prefixed by '#'. Trace how xaxis type='category' and autotypenumbers='strict' are handled for both bar data and shapes with xref='x'; done means numeric-looking strings remain categorical and the rectangle spans the intended categories.
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