name: title class: title-slide background-image: url(pics/templ_title.png) background-position: 50% 100% background-size: 100% 35% <style> .remark-slide-number { margin-left: -60px !important; margin-right: auto !important; } </style> <hr style="margin: 150px 0px 0px 0px;"> # Bringing Interactivity to Classic Clinical Plots with <span style='color:#5f976c'>Highcharts</span> and <span style='color:#1f65cc'>R</span> ## Iaroslav Domin <img src="pics/templ_title_text.png" style="position: absolute; bottom: 3%; width: 85%"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f5/Hoffmann-La_Roche_logo.svg/1920px-Hoffmann-La_Roche_logo.svg.png" style="position: fixed; top: 2.8%; right: 1.9%" width="65"> --- background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/f/f5/Hoffmann-La_Roche_logo.svg/1920px-Hoffmann-La_Roche_logo.svg.png) background-size: 65px background-position: 98% 3% name: layout layout: true <img src="pics/templ_watermark.png" style="position: fixed; bottom: 0%; right: 0%" width="120"> --- name: agenda exclude: false # Agenda <div style='font-size:28px; line-height: 50px;'> 1. Interactive visualization in R: overview 2. Highcharts principles 3. Clinical graphs with Highcharts 4. Helpful resources <div/> --- name: clinical-graphs class: center, middle #Interactive Visualization in R --- name: gg-shiny exclude: false # static plot + shiny <img src="pics/ggshiny-1.png" style="display:inline; position: absolute; top: 140px; left: 40px;" height="270"> <img src="pics/arrow-right-blue.svg" style="position: absolute; left: 415px; top: 230px" width="100"> <img src="pics/ggshiny-2.gif" style="display:inline; position: absolute; top: 140px; right: 20px;" height="270"> <div style="position: absolute; top:470px; left: 110px; font-size: 200%; line-height: 60px;"> ☑ convenient <br/> ☒ limited </div> --- name: fortunately exclude: true # Interfaces <img src="https://upload.wikimedia.org/wikipedia/commons/9/99/Unofficial_JavaScript_logo_2.svg" style="display:inline; position: absolute; top: 160px;" height="130"> <img src="pics/python-logo.svg" style="display:inline; position: absolute; top: 350px; left: 85px;" height="150"> <span style="position: absolute; top:500px; left: 110px; font-size: 450%;"> ... </span> <img src="pics/arrow-right-blue.svg" style="position: absolute; left: 290px; top: 270px" width="270"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/R_logo.svg/724px-R_logo.svg.png" style="position: absolute; right: 50px; top: 260px" height="200"> --- name: alter exclude: false name: plotly + bokeh # Popular libraries available in R .pull-left[ <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Plotly-logo-01-square.png/220px-Plotly-logo-01-square.png" height = 200> ```r library(plotly) ``` * JavaScript * free (paid support) * official R package * can translate ggplot2 to plotly ] .pull-right[ <img src="http://pyviz.org/assets/bokeh.png" height = 200> ```r library(rbokeh) ``` * Python * open-source * fast * not so fancy ] ??? [others](http://www.rebeccabarter.com/blog/2017-04-20-interactive/) --- name: hc-intro exclude: false # Highcharts .pull-left[ <img src="https://cdn.freebiesupply.com/logos/large/2x/highcharts-logo-svg-vector.svg" height = 300> ] .pull-right[ ```r library(highcharter) ``` <div style='line-height: 40px;'> * <span style='color:#3d94d1; font-size:28px;'>**looks awesome!**</span> * <span style='color:#d62d20; font-size:28px;'>**not free**</span> * <span style='font-size:22px;'>JavaScript</span> ] </div> --- name: clinical-graphs class: center, middle #Highcharts vs Ggplot2 --- name: gg-philosophy-1 exclude: false # ggplot2 philosophy <img src="pics/ggplot2_phil_2.png" height = 500> --- name: gg-philosophy-2 exclude: false # ggplot2 philosophy ```r ggplot(df, aes(x = s_length, y = s_width, color = species)) ``` <img src="index_files/figure-html/unnamed-chunk-7-1.png" style="position: absolute; bottom: 3%;" /> --- name: gg-philosophy-3 exclude: false # ggplot2 philosophy ```r ggplot(df, aes(x = s_length, y = s_width, color = species)) + geom_point() ``` <img src="index_files/figure-html/unnamed-chunk-8-1.png" style="position: absolute; bottom: 3%;" /> --- name: gg-philosophy-4 exclude: false # ggplot2 philosophy ```r ggplot(df, aes(x = s_length, y = s_width, color = species)) + geom_point() + geom_smooth() ``` <img src="index_files/figure-html/unnamed-chunk-9-1.png" style="position: absolute; bottom: 3%;" /> --- name: hc-philosophy exclude: false # Highcharts philosophy ### Dataframes? ### No, lists! ```js series: [{ name: 'SUBJ-01', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133] }, { name: 'SUBJ-02', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121] }, { name: 'SUBJ-03', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147] }, { name: 'SUBJ-04', data: [null, null, 7988, 12169, 15112, 22452, 34400] }], ... ``` <script type="text/javascript"> series: [{ name: 'SUBJ-01', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133] }, { name: 'SUBJ-02', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121] }, { name: 'SUBJ-03', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147] }, { name: 'SUBJ-04', data: [null, null, 7988, 12169, 15112, 22452, 34400] }], ... </script> ??? historically - HC initially built for timeseries data nested lists is very natural thing for js as far as i can judge (at least more than for R) --- name: optional exclude: false # Options are Optional .pull-left[ ```r highchart( list( series = list( * list(name = "A", * data = c(2, 3, 1)), * list(name = "B", * data = c(5, 0, 2)) ) ) ) ``` ] .pull-right[
] --- name: more-lists-1 exclude: false # We need to go deeper ```r highchart( list( series = list( list(name = "A", data = list( 2, * list(y = 3, * marker = list(radius = 20), * color = "red", * name = "RED POINT"), 1)), list(name = "B", data = c(5, 0, 2)) ) ) ) ``` ??? (?) alter label option + add something interactive further I will show a more impressive example of what can be done with individual point options we --- name: more-lists-2 exclude: false # We need to go deeper
??? the idea is that you can pick arbitrary part of the plot and set whatever options you want --- name: hc-helpers-1 exclude: false # It's not that bad actually ```r highchart() %>% hc_add_series(data = c(2, 3, 1), name = "A") %>% hc_add_series(data = c(5, 0, 2), name = "B") %>% hc_chart(type = "column") %>% hc_title(text = "Super Meaningful Chart") ``` --- name: hc-helpers-2 exclude: false # It's not that bad actually ```r *highchart() %>% hc_add_series(data = c(2, 3, 1), name = "A") %>% hc_add_series(data = c(5, 0, 2), name = "B") %>% hc_chart(type = "column") %>% hc_title(text = "Super Meaningful Chart") ``` --- name: hc-helpers-3 exclude: false # It's not that bad actually ```r highchart() %>% * hc_add_series(data = c(2, 3, 1), name = "A") %>% * hc_add_series(data = c(5, 0, 2), name = "B") %>% hc_chart(type = "column") %>% hc_title(text = "Super Meaningful Chart") ``` --- name: hc-helpers-4 exclude: false # It's not that bad actually ```r highchart() %>% hc_add_series(data = c(2, 3, 1), name = "A") %>% hc_add_series(data = c(5, 0, 2), name = "B") %>% * hc_chart(type = "column") %>% hc_title(text = "Super Meaningful Chart") ``` --- name: hc-helpers-5 exclude: false # It's not that bad actually ```r highchart() %>% hc_add_series(data = c(2, 3, 1), name = "A") %>% hc_add_series(data = c(5, 0, 2), name = "B") %>% hc_chart(type = "column") %>% * hc_title(text = "Super Meaningful Chart") ``` --- name: hc-helpers-6 exclude: false # It's not that bad actually ```r highchart() %>% hc_add_series(data = c(2, 3, 1), name = "A") %>% hc_add_series(data = c(5, 0, 2), name = "B") %>% hc_chart(type = "column") %>% hc_title(text = "Super Meaningful Chart") ```
??? the author couldnt have just left us with these scary lists. Added some helper functions. Would’ve been too cruel what's cool in letting people write js-like in R? --- name: hchart-gg exclude: false # Hey, I can do some ggplot2! ```r hchart(df, "line", hcaes(x = x, y = y, group = arm)) ```
--- name: clinical-graphs class: center, middle #Clinical Graphs --- name: surv-1 exclude: false # Survival Curve ```r library(survival) library(dplyr) lung <- survival::lung lung <- mutate(lung, sex = ifelse(sex == 1, "Male", "Female")) fit <- survfit(Surv(time, status) ~ sex, data = lung) fit ``` ``` ## Call: survfit(formula = Surv(time, status) ~ sex, data = lung) ## ## n events median 0.95LCL 0.95UCL ## sex=Female 90 53 426 348 550 ## sex=Male 138 112 270 212 310 ``` --- name: surv-2 exclude: false # Survival ```r hchart(fit, ranges = TRUE) ``` <img src = "pics/hc_surv.png" style = "width: 95%; height: auto;"> --- name: spider-gg exclude: false # Spiderplot (ggplot2) ![](index_files/figure-html/unnamed-chunk-26-1.png)<!-- --> --- name: spider-hc exclude: false # Spiderplot (Highcharts)
??? (!) fix lower y limit to -100 zoomable - emphasize --- name: waterfall exclude: false # Waterfall Plot
--- name: help class: center, middle #Where to Get Help --- name: highcharter-lp exclude: false # jkunst.com/highcharter <img src="pics/highcharter-lp.png" style = "height: 100%; width: 100%;"> --- name: help-purrr exclude: false # purrr package <img src="pics/purrr_cs_2.png" style = "height: 85%; width: 85%;"> --- name: help-doc exclude: false # documentation + jsfiddle/codepen <img src="pics/jsfiddle.gif" style = "height: 100%; width: 100%;"> ??? some javascript knowledge will help but it isn't necessary --- name: summary exclude: false # Try it Out! ```r install.packages("highcharter") ``` Find the slides at: [idmn.me](https://idmn.me) --- name: questions <img src="pics/templ_questions.png" style="position: fixed; top:40%; left: 25%"> --- name: doing <h1><span style='color:#3d94d1; position: fixed; top: 40%; left: 15%'>Doing now what patients need next </span></h1>