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'):
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")
What I'd like to do is give viewers of the html file (produced by the markdown) the ability to highlight some specific dates (from 'historic') and compare it to the data from 'recent'. Now I realise this would probably be possible in a shiny app, however that is not suitable for my purposes and I was wondering whether jQuery's 'Datepicker' plugin (or something similar) might offer the solution.
Does anyone know how (or if) I can achieve this?
https://www.aliciaschep.com/blog/js-rmarkdown/
CodePudding user response:
With thanks to r2evans, it seems I had to slice the dataset down in to a more manageable selection then use the crossstalk library to add interactivity.