Skip to content

Instantly share code, notes, and snippets.

@nstefi
Created June 26, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nstefi/f67f8cbc171a2dc6e4b8cc876dfd0c81 to your computer and use it in GitHub Desktop.
Save nstefi/f67f8cbc171a2dc6e4b8cc876dfd0c81 to your computer and use it in GitHub Desktop.
R reproducible example for plot_ly x axis issue
library(plotly)
chart_data <- structure(list(`Month-Day` = c("05-01", "05-15", "05-31", "06-01",
"06-15", "07-01", "07-15", "08-01", "08-15", "09-01", "09-15",
"10-01", "10-15", "11-01", "11-15", "12-01", "12-15", "01-01",
"01-15", "02-01", "02-15", "03-01", "03-15", "04-01", "04-15",
"05-01", "05-15", "06-01", "06-15", "07-01", "07-15"), FiscalYear_Days = c(0,
14, 30, 31, 45, 61, 75, 92, 106, 123, 137, 153, 167, 184, 198,
214, 228, 245, 259, 276, 290, 304, 318, 335, 349, 365, 379, 396,
410, 426, 440), Last_Year = c(16, 17, 22, 25, 28, 31, 34, 37,
40, 44, 47, 50, 53, 56, 60, 63, 66, 69, 72, 76, 79, 82, 85, 88,
92, 95, 98, 101, 104, 108, 111), This_Year = c(10, 14, 18, 18,
22, 24, 27, 30, 33, 36, 38, 41, 44, 47, 50, 52, 55, 58, 61, 64,
66, 69, 72, 75, 78, 80, 83, 86, 89, 92, 94)), row.names = c(NA,
31L), class = "data.frame")
plot_ly(chart_data,
x = ~`Month-Day`,
y = ~Last_Year,
type = 'scatter',
mode = 'lines'
) %>%
layout(xaxis = list(categoryarray = chart_data$FiscalYear_Days, categoryorder = "array"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment