I am wondering if there is anyway to alter the slider (frame) tick labels used on animations through code in the layout or animation options? All of the Plotly examples have numeric tick labels, but what if I wanted the tick labels to read text, such as months?
The way the ~frame API and the accumulate_by function seem to work best is with integers and not strings.
Have you figured anything out? I’m trying to do the exact same thing with months. I’d prefer it to display the month spelled out instead of just the number. When I use an ordered factor of the month names, it ends up adding a bunch of traces to the chart and there is no animation. Here’s some code I’m working with:
snow_plot <- snow_depth %>% plot_ly(
x = ~year,
y = ~avg_depth,
color = ~avg_temp,
frame = ~month_char,
text = ~paste('<i>Month</i>: ', month_char,
'<br><b>Avg. Depth</b>: ', avg_depth,
'<br><b>Avg. Temp</b>: ', avg_temp),
hoverinfo = 'text',
type = 'bar'
) %>%
layout(
title = "Average Snow Depth by Week",
yaxis = list(title = "Average Depth (mm)")
) %>%
animation_opts(
frame = 1000
)
In this code, month_char is the ordered factor of months using three character abbreviations (e.g., Mar, Apr, May, etc.).
A helpful user on StackOverflow was able to answer my version of the question. It still isn’t a perfect solution and is kind of a workaround. Below is the code ismirsehregal provided: