Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

category axis and shapes not playing well when data representing numbers and xref = "x" #2324

Open
nlooije opened this issue Dec 9, 2023 · 0 comments

Comments

@nlooije
Copy link

nlooije commented Dec 9, 2023

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:

newplot (6)

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:

newplot (7)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant