'Masking/Hiding and highlighting multiple time series with plotly. Is this possible?
I have a very large dataframe of historical data of which this is a clipping (data=historic):
structure(list(date = structure(c(18948, 18948, 18948, 18948,
18949, 18949, 18949, 18949, 18950, 18950, 18950, 18950, 18951,
18951, 18951, 18951, 18952, 18952, 18952, 18952, 18953, 18953,
18953, 18953, 18954, 18954, 18954, 18954, 18955, 18955, 18955, 18955), class = "Date"),
cumvol = c(17.572, 17.578, 17.672, 17.829, 17.471, 17.477,
17.489, 17.497, 17.527, 17.546, 17.552, 17.557, 17.562, 17.564,
17.573, 17.658, 17.688, 17.698, 17.714, 17.743, 17.757, 17.764,
17.774, 17.776, 17.787, 17.798, 17.809, 17.82, 17.825, 17.841, 18.101, 18.243
), time = structure(c(29674, 29674, 29691, 29719, 29674,
29674, 29691, 29719, 29730, 29746, 29749, 29757, 29763, 29768,
29782, 29782, 29795, 29796, 29805, 29916, 29919, 29922, 29924,
29933, 30004, 30016, 30037, 30048, 30053, 30055, 30075, 30078, 30081), class = c("hms",
"difftime"), units = "secs")), class = c("data.table", "data.frame"
), row.names = c(NA, -30L), .internal.selfref = <pointer: 0x000001d92b2d1ef0>)
I am currently plotting some recent data over the top of it (data=recent):
structure(list(date = structure(c(19038, 19038, 19038, 19038), class = "Date"),
cumvol = c(0.029, 0.034, 0.07, 0.075), time = structure(c(29674,
29674, 29691, 29719), class = c("hms", "difftime"), units = "secs")), class = c("data.table",
"data.frame"), row.names = c(NA, -4L), .internal.selfref = <pointer: 0x000001d92b2d1ef0>)
Using the following code (most_recent simply takes the most recent datapoint from 'recent'):
chart <- ggplot()+geom_line(data=historic,aes(x=time, y=cumvol, group=date),color='#BAB0AC', alpha=0.5)+
geom_line(data=recent,aes(x=time, y=cumvol, group=date),size=1.2,color='#E15758')+
geom_point(data=most_recent, aes(x=time,y=cumvol), color='#E15759',size=3)+geom_hline(yintercept = 0)+ theme(title=element_text(size=12),panel.background = element_rect(fill='white',color='black'),legend.position='right')+
labs(title = "Morning Vol",subtitle = "Cum Vol so far", x = "Time", y = "Vol")
plotly::gplotly(chart)
I was wondering how (or if) it's possible to highlight as well as hiding particular dates at a whim via plotly, maybe using tickboxes under the chart.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
