i haven't found the answer to the following question when googling:
Question: How do find the axis limits of an element created by plot_ly
(it must be hidden in there, somewhere, or?)?
Background:
I'm using plot_ly to create a lot of different timelines and I'm also updating them regularly with new data coming in.
fig <- plot_ly(....)
Now I want to mark several milestones in the plots as vertical lines. So far I haven't found how to "abline" in plot_ly - figures without giving the max x-value.
As I'm updating frequently, the maximum in the plot might change with new data.
I would like to avoid runing max
on all the several different timelines in the plot for several reasons.
Thanks a lot!
Code example:
fig <- plot_ly(df_timeseries, x = ~date)
fig <- fig %>% add_trace(y = ~count_mice, name = "Counts of mice",
mode = 'lines+markers' )
fig <- fig %>% add_trace(y = ~count_cats, name = "Counts of cats",
mode = 'lines+markers' )
fig <- fig %>% layout(title = "<b>Count of specimen</b>",
yaxis = list (title = "count"),
xaxis = list (title = "date"))
# and here is the problem. I want to add a vertical line, without having to specify y1
fig.update_layout(shapes=[
dict(
type= 'line',
yref= 'paper', y0= 0, y1= 100,
xref= 'x', x0= as.Date("2020-08-04"), x1= as.Date("2020-08-04")
)
fig