-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopHIVE.qmd
More file actions
2131 lines (1553 loc) · 72.6 KB
/
PopHIVE.qmd
File metadata and controls
2131 lines (1553 loc) · 72.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "PopHIVE: Population Health Information and Visualization Exchange"
title-block-banner: "#0c233f"
format:
html:
embed-resources: true
page-layout: full
toc: true
toc-expand: true
smooth-scroll: true
theme: cosmo
project:
execute-dir: project
css: styles.css
server: shiny
---
```{r setup}
#| context: setup
#| include: false
knitr::opts_chunk$set(fig.width = 12, fig.align = "center")
# Field "panel" has value toolbar, which must instead be one of: `tabset`, `input`, `sidebar`, `fill`, `center`
#https://r-graph-gallery.com/183-choropleth-map-with-leaflet.html
suppressPackageStartupMessages({
library(tidyverse)
library(plotly)
library(shiny)
library(tidyverse)
library(scales)
library(janitor)
library(MMWRweek)
library(arrow)
#library(rnaturalearth)
library(parquetize)
library(viridisLite)
library(tigris)
library(usmap)
library(cowplot)
library(leaflet)
library(viridis)
library(sf)
library(ggrepel)
library(readxl)
library(ggalluvial)
library(waffle)
})
#library(cdcfluview)
#install.packages("remotes")
#remotes::install_github("hrbrmstr/cdcfluview")
#hhs_regions$state <- state.abb[match(hhs_regions$state_or_territory,state.name)]
#state.hhs.codes <- aggregate(hhs_regions$state, #list(hhs_regions$region), paste, collapse=",")
#state.hhs.codes$x <- gsub('NA,','',state.hhs.codes$x)
#state.hhs.codes$x <- gsub(',NA','',state.hhs.codes$x)
#saveRDS(state.hhs.codes, './hhs_regions.rds')
yale_colors <- c(
"#00356B",
"#286DC0",
"#63AAFF",
"#C4DDFC",
"#DDDDDD"
)
yale_gradient <- c("#DDDDDD",
"#C4DDFC",
"#63AAFF",
"#286DC0",
"#00356B") # Adjust order for your desired gradient
#datasets for use in the global environment
"%!in%" <- function(x,y)!("%in%"(x,y))
#Defines a general function that can be reused for age plots
age_ts_plot <- function(ds.in=epic_ed_combo, scale_var=input$scale.rsv, outcome_select='RSV', tslabel='RSV'){
plot_ds <- ds.in %>%
filter(geography==input$state.select5 & date >=as.Date('2023-07-01') & outcome_name==outcome_select, age_level != 'Total' ) %>%
mutate(plotvar = if_else(scale_var==T,Outcome_value3, Outcome_value2 ))
ts_compare <- plot_ds %>%
ggplot()+
geom_line(aes(x=date, y=plotvar, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab(paste0('Percent of ED visits for ', tslabel))+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for ', tslabel, ' in ',input$state.select5))
ggplotly(ts_compare)
}
```
## Welcome to PopHIVE
This platform is designed to give its users timely, clear, and useful insights into community health. We bring together data from multiple sources—like public health reports, electronic health records, sewage testing, online search trends, surveys, and predictive models—to help paint a fuller picture of health trends. We're just getting started and will be adding even more data and disease insights in the coming months. This project is led by the Yale School of Public Health.
------------------------------------------------------------------------
## Respiratory infections
::: panel-tabset
### Respiratory Syncytial Virus (RSV)
```{r}
#| context: data
#| include: false
url_files <- 'https://raw.githubusercontent.com/ysph-dsde/PopHIVE_DataHub/refs/heads/main/Data/Plot%20Files/'
nrevss_rsv_ts <- read_csv(paste0(url_files,'NREVSS/rsv_ts_nrevss_test_rsv.csv'))
rsv_all_indicators_state <- read_csv(paste0(url_files,'Comparisons/rsv_combined_all_outcomes_state.csv'))
flu_all_indicators_state <- read_csv(paste0(url_files,'Comparisons/flu_combined_all_outcomes_state.csv'))
covid_all_indicators_state <- read_csv(paste0(url_files,'Comparisons/covid_combined_all_outcomes_state.csv'))
rsvnet_age <- read_csv(paste0(url_files,'RESP-NET%20Programs/rsv_hosp_age_respnet.csv'))
epic_ed_combo <- read_csv(paste0(url_files,'Cosmos%20ED/rsv_flu_covid_epic_cosmos_age_state.csv'))
rsv_flu_covid_county_filled_nssp <- read_csv(paste0(url_files,'Cosmos%20ED/rsv_flu_covid_county_filled_map_nssp.csv'))
```
```{r rsv_plots}
#| context: server
#| include: false
########################################
##RSV
########################################
output$distPlotRSV3 <- renderPlotly({
point_plot <- nrevss_rsv_ts %>% filter(hhs_abbr==input$hhs.region.select & epiyr == max(epiyr, na.rm=T) ) %>%
filter(epiwk==max(epiwk))
rsv_ts1 <- nrevss_rsv_ts %>%
filter(x==input$hhs.region.select) %>%
ggplot(aes(x=epiwk, y=scaled_cases, group=as.factor(epiyr), color=as.factor(epiyr)))+
geom_line()+
theme_minimal()+
xlab('Weeks since July')+
ylab('RSV positive tests')+
scale_colour_viridis_d() +
geom_point(data=point_plot,aes(x=epiwk, y=scaled_cases) ,col='red') +
guides(color=guide_legend(title="Season starting:"))
ggplotly(rsv_ts1)
})
############################
output$distPlotRSV_dwh <- renderPlotly({
pal1 <- RColorBrewer::brewer.pal(n=length(unique(rsv_all_indicators_state$outcome_label1))+1,'Set1' )
pal1 <- pal1[-6]
rsv_ts_comp <- rsv_all_indicators_state %>%
filter(geography==input$state.select2 ) %>%
mutate(ds_label = if_else(outcome_label1=='Google Searches 1', 'Google 1',
if_else(outcome_label1=='Google Searches 2', 'Google 2',
if_else(outcome_label1=='Pct of ED visits', 'ED visits (CDC/NSSP)',
if_else(outcome_label1=='Pct of ED visits (Epic)', 'ED visits (Epic cosmos)',
if_else(outcome_label1=='Hospitalizations', 'Hospitalization Resp-Net)', outcome_label1
)))))
) %>%
ggplot()+
geom_line(aes(x=date, y=outcome_3m_scale, color=ds_label,linetype=ds_label, group=ds_label,
text=paste0(geography, "<br>",
source, "<br>",
outcome_label1, "<br>",
Outcome_value1, "<br>",
date, "<br>"
))) +
theme_minimal() +
xlab('Date')+
labs(color='Source') +
ylab('RSV activity (scaled to 100)')+
scale_color_manual(values=pal1) +
ggtitle(input$state.select2)
ggplotly(rsv_ts_comp,tooltip='text')
})
#hospitalization by age
output$distPlotRSV_hosp_age <- renderPlotly({
rsv_ts_comp <- rsvnet_age %>%
filter(state==input$state.select3 & date >=as.Date('2023-07-01')) %>%
ggplot()+
geom_line(aes(x=date, y=scale_age, group_by=Level, color=Level)) +
theme_minimal()+
xlab('Date')+
ylab('RSV activity (CDC surveillance)')+
scale_colour_viridis_d() +
ggtitle(paste0(input$state.select3, ' CDC hospital surveillance'))
ggplotly(rsv_ts_comp)
})
#epic ED by age
output$distPlotRSV_epic_ED_age <- renderPlotly({
if(input$scale.rsv==F){
rsv_epic_ts_comp <- epic_ed_combo %>%
filter(geography==input$state.select3 & date >=as.Date('2023-07-01') & outcome_name=='RSV' & age_level !='Total') %>%
ggplot()+
geom_line(aes(x=date, y=Outcome_value2, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab('Percent of ED visits for RSV (Epic Cosmos)')+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for RSV in ',input$state.select3))
ggplotly(rsv_epic_ts_comp)
}else{
rsv_epic_ts_comp <- epic_ed_combo %>%
filter(geography==input$state.select3 & date >=as.Date('2023-07-01') & outcome_name=='RSV' & age_level !='Total') %>%
ggplot()+
geom_line(aes(x=date, y=Outcome_value3, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab('Rescaled ED visits for RSV (Epic Cosmos)')+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for RSV in ',input$state.select3))
ggplotly(rsv_epic_ts_comp)
}
})
output$epicMapRSV <- renderPlotly({
map_data <- epic_ed_combo %>%
filter(date == input$selected_date & age_level == '<1 Years' & outcome_name=='RSV') %>%
mutate(state = state.abb[match(geography, state.name)] ,
#Note, if >20%, cap at 20 for plotting!
Outcome_value2 = if_else(Outcome_value2>10,10, Outcome_value2)
#Outcome_value2 = if_else(Outcome_value4<5, Outcome_value4*0.01 ,Outcome_value2) #deals with cell suppression
) %>%
filter(!is.na(state)) %>%
as.data.frame()
max.val <- max(epic_ed_combo$Outcome_value2, na.rm=T)
pal1 <- viridis_pal()(4)
date.print <- input$selected_date
p1 <- usmap::plot_usmap(regions = "state", data = map_data, values = "Outcome_value2") +
scale_fill_gradientn(
colors = pal1,
values = scales::rescale(c(0, 2.5, 5, 7.5, 10)),
limits = c(0, 10),
na.value = "#440154FF"
) +
ggtitle(paste("RSV ED Visit Percentage <1 year olds on", date.print))
ggplotly(p1)
})
```
::: panel-tabset
#### Overall Trends
```{r}
selectInput("state.select2", "State:",
choices=unique(epic_ed_combo$geography), selected='New York')
```
```{r}
#| panel: fill
plotlyOutput("distPlotRSV_dwh")
```
Viral levels in the community can be measured in different ways, which is important because no measure is perfect. By triangulating data from sources like emergency department (ED) visits, hospitalizations, and wastewater surveillance, we can get a more complete picture of how and when a virus is spreading, which can help you make better-informed decisions. Epic data come from the [Epic Cosmos platform](https://www.epicresearch.org/about-us). The Google Trends data are obtained from the Google Health Trends API (volume of searches for 'rsv', subtracting volume of searches for category "respiratory syncytial virus vaccine" (Knowledge graph: /g/11j30ybfx6) ). Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/dwh_combined_plot1_long.csv).
#### Trends in positive tests
```{r}
selectInput("hhs.region.select", "Region:",
choices=unique(nrevss_rsv_ts$hhs_abbr), selected='CT,ME,MA,NH,RI,VT')
```
```{r}
#| panel: fill
plotlyOutput("distPlotRSV3")
```
These data come from the NREVSS surveillance system, which is comprised of laboratories around the US. Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/rsv_ts_nrevss_test_rsv.csv).
#### By age
```{r}
selectInput("state.select3", "State:",
choices=state.name, selected='New York')
checkboxInput("scale.rsv", "Rescale?",
value=T)
```
```{r}
#| panel: fill
plotlyOutput("distPlotRSV_epic_ED_age")
plotlyOutput("distPlotRSV_hosp_age")
```
The hospitalization data comes from the RSV-NET, a CDC-supported network of sites around the US that tracks hospitalizations from RSV, influenza, and COVID-19. Data are smoothed with a 3 week average for vizualization. Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/rsv_ts_nrevss_test_rsv.csv).
#### Map of ED visits (state)
```{r}
sliderInput("selected_date", label=NULL,
min = min(epic_ed_combo$date),
max = max(epic_ed_combo$date),
value = as.Date('2024-10-19'),
step=7,
timeFormat = "%Y-%m-%d",
animate = animationOptions(interval = 1000, loop = TRUE, playButton = 'P',pauseButton = 'S'))
```
```{r}
#| panel: fill
plotlyOutput("epicMapRSV")
```
Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/epic_ed_combo_rsv_flu_covid.csv).
#### Map of ED visits (county)
```{r}
#| panel: fill
subtitle= 'National Syndromic Surveillance Program (CDC)'
scaletitle= 'Percent'
pal1 <- viridis::viridis_pal()(4)
dates <- seq.Date(from=as.Date('2022-10-01'), to=Sys.Date(),by='week')
p1 <- rsv_flu_covid_county_filled_nssp %>%
filter(week_end==max(week_end)) %>%
mutate(percent_visits_rsv = if_else(percent_visits_rsv>2,2,percent_visits_rsv)) %>%
usmap::plot_usmap(regions='county', data=.,values='percent_visits_rsv',
color = NA, # Faint border color
size = 0 )+ # Thin border lines) +
theme(panel.background = element_rect(color = "white", fill = "white")) +
scale_fill_gradientn(
scaletitle,
colors = pal1,
values = scales::rescale(c(0, 0.33, 0.66, 0.99,2)),
limits = c(0, 2),
na.value = "darkgray"
)
plotly::ggplotly(p1)%>%
layout(title = list(text = paste0(paste0('RSV ED visits by jurisdiction ', max(rsv_flu_covid_county_filled_nssp$week_end)),
'<br>',
'<sup>',
subtitle,'</sup>')))
```
The maps shows the percentage of ED visits in each jurisdiction caused by RSV. Some states have county-level data available, while others have state-level data only. This includes data aggregated across all age groups. Ideally this would be broken out separately for infants and older adults. The data come from the national syndromic surveillance network. Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/rsv_county_filled_map_nssp.csv).
#### Maps of Google searches
*Coming soon*
```{r}
# sliderInput("date.select2", label=NULL,
# min = min(epic_ed_combo$date),
# max = max(epic_ed_combo$date),
# value = as.Date('2024-10-19'),
# step=7,
# timeFormat = "%Y-%m-%d")
```
```{r}
#| panel: fill
#plotlyOutput('googleMapRSV')
```
People searching for information on RSV often correlates well with actual clinical activity for RSV.
:::
### Influenza (Seasonal Flu)
```{r flu_plots}
#| context: server
#| include: false
########################################
##flu
########################################
############################
output$distPlotflu_dwh <- renderPlotly({
pal1 <- RColorBrewer::brewer.pal(n=length(unique(flu_all_indicators_state$outcome_label1))+1,'Set1' )
pal1 <- pal1[-6]
flu_ts_comp <- flu_all_indicators_state %>%
filter(geography==input$state.select2.flu ) %>%
mutate(ds_label = if_else(outcome_label1=='Google Searches 1', 'Google 1',
if_else(outcome_label1=='Google Searches 2', 'Google 2',
if_else(outcome_label1=='Pct of ED visits', 'ED visits (CDC/NSSP)',
if_else(outcome_label1=='Pct of ED visits (Epic)', 'ED visits (Epic cosmos)',
if_else(outcome_label1=='Hospitalizations', 'Hospitalization Resp-Net)', outcome_label1
)))))
) %>%
ggplot()+
geom_line(aes(x=date, y=outcome_3m_scale, color=ds_label,linetype=ds_label, group=ds_label,
text=paste0(geography, "<br>",
source, "<br>",
outcome_label1, "<br>",
Outcome_value1, "<br>",
date, "<br>"
))) +
theme_minimal() +
xlab('Date')+
labs(color='Source') +
ylab('Influenza activity (scaled to 100)')+
scale_color_manual(values=pal1) +
ggtitle(input$state.select2)
ggplotly(flu_ts_comp,tooltip='text')
})
#epic ED by age
output$distPlotflu_epic_ED_age <- renderPlotly({
if(input$scale.flu==F){
flu_epic_ts_comp <- epic_ed_combo %>%
filter(geography==input$state.select3.flu & date >=as.Date('2023-07-01') & outcome_name=='FLU' & age_level !='Total') %>%
ggplot()+
geom_line(aes(x=date, y=Outcome_value2, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab('Percent of ED visits for flu (Epic Cosmos)')+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for flu in ',input$state.select3))
ggplotly(flu_epic_ts_comp)
}else{
flu_epic_ts_comp <- epic_ed_combo %>%
filter(geography==input$state.select3.flu & date >=as.Date('2023-07-01') & outcome_name=='FLU' & age_level !='Total') %>%
ggplot()+
geom_line(aes(x=date, y=Outcome_value3, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab('Rescaled ED visits for influenza (Epic Cosmos)')+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for influenza in ',input$state.select3))
ggplotly(flu_epic_ts_comp)
}
})
output$epicMapflu <- renderPlotly({
map_data <- epic_ed_combo %>%
filter(date == input$selected_date.flu & age_level == 'Total' & outcome_name=='FLU') %>%
mutate(state = state.abb[match(geography, state.name)] ,
#Note, if >20%, cap at 20 for plotting!
Outcome_value2 = if_else(Outcome_value2>20,20, Outcome_value2)
#Outcome_value2 = if_else(Outcome_value4<5, Outcome_value4*0.01 ,Outcome_value2) #deals with cell suppression
) %>%
filter(!is.na(state)) %>%
as.data.frame()
max.val <- max(epic_ed_combo$Outcome_value2, na.rm=T)
pal1 <- viridis_pal()(4)
date.print <- input$selected_date.flu
p1 <- usmap::plot_usmap(regions = "state", data = map_data, values = "Outcome_value2") +
scale_fill_gradientn(
colors = pal1,
values = scales::rescale(c(0, 5, 10, 15, 20)),
limits = c(0, 20),
na.value = "#440154FF"
) +
ggtitle(paste("Influenza ED Visit Percentage in all ages on", date.print))
ggplotly(p1)
})
```
::: panel-tabset
#### Overall Trends
```{r}
selectInput("state.select2.flu", "State:",
choices=unique(epic_ed_combo$geography), selected='New York')
```
```{r}
#| panel: fill
plotlyOutput("distPlotflu_dwh")
```
| |
|------------------------------------------------------------------------|
| Viral levels in the community can be measured in different ways, which is important because no measure is perfect. By triangulating data from sources like emergency department (ED) visits, hospitalizations, and wastewater surveillance, we can get a more complete picture of how and when a virus is spreading, which can help you make better-informed decisions. Epic data come from the [Epic Cosmos platform](https://www.epicresearch.org/about-us). Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/dwh_combined_plot1_long.csv). |
\#### Trends in positive tests
#### By age
```{r}
selectInput("state.select3.flu", "State:",
choices=state.name, selected='New York')
checkboxInput("scale.flu", "Rescale?",
value=T)
```
```{r}
#| panel: fill
plotlyOutput("distPlotflu_epic_ED_age")
```
Data are smoothed with a 3 week average for vizualization.
#### Map of ED visits (state)
```{r}
sliderInput("selected_date.flu", label=NULL,
min = min(epic_ed_combo$date),
max = max(epic_ed_combo$date),
value = as.Date('2024-10-19'),
step=7,
timeFormat = "%Y-%m-%d",
animate = animationOptions(interval = 1000, loop = TRUE, playButton = 'P',pauseButton = 'S'))
```
```{r}
#| panel: fill
plotlyOutput("epicMapflu")
```
Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/epic_ed_combo_rsv_flu_covid.csv).
#### Map of ED visits (county)
```{r}
#| panel: fill
subtitle= 'National Syndromic Surveillance Program (CDC)'
scaletitle= 'Percent'
pal1 <- viridis::viridis_pal()(4)
dates <- seq.Date(from=as.Date('2022-10-01'), to=Sys.Date(),by='week')
p1 <- rsv_flu_covid_county_filled_nssp %>%
filter(week_end==max(week_end)) %>%
mutate(percent_visits_flu = if_else(percent_visits_flu>3,3,percent_visits_flu)) %>%
usmap::plot_usmap(regions='county', data=.,values='percent_visits_flu',
color = NA, # Faint border color
size = 0 )+ # Thin border lines) +
theme(panel.background = element_rect(color = "white", fill = "white")) +
scale_fill_gradientn(
scaletitle,
colors = pal1,
values = scales::rescale(c(0, 0.75, 1.5, 2.25,3)),
limits = c(0,3),
na.value = "darkgray"
)
plotly::ggplotly(p1)%>%
layout(title = list(text = paste0(paste0('Influenza ED visits by jurisdiction ', max(rsv_flu_covid_county_filled_nssp$week_end)),
'<br>',
'<sup>',
subtitle,'</sup>')))
```
The maps shows the percentage of ED visits in each jurisdiction caused by influenza Some states have county-level data available, while others have state-level data only. This includes data aggregated across all age groups. Ideally this would be broken out separately for infants and older adults. The data come from the national syndromic surveillance network. Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/rsv_county_filled_map_nssp.csv).
:::
### Covid-19
```{r covid_plots}
#| context: server
#| include: false
########################################
##covid
########################################
############################
output$distPlotcovid_dwh <- renderPlotly({
pal1 <- RColorBrewer::brewer.pal(n=length(unique(covid_all_indicators_state$outcome_label1))+1,'Set1' )
pal1 <- pal1[-6]
covid_ts_comp <- covid_all_indicators_state %>%
filter(geography==input$state.select2.covid ) %>%
mutate(ds_label = if_else(outcome_label1=='Google Searches 1', 'Google 1',
if_else(outcome_label1=='Google Searches 2', 'Google 2',
if_else(outcome_label1=='Pct of ED visits', 'ED visits (CDC/NSSP)',
if_else(outcome_label1=='Pct of ED visits (Epic)', 'ED visits (Epic cosmos)',
if_else(outcome_label1=='Hospitalizations', 'Hospitalization Resp-Net)', outcome_label1
)))))
) %>%
ggplot()+
geom_line(aes(x=date, y=outcome_3m_scale, color=ds_label,linetype=ds_label, group=ds_label,
text=paste0(geography, "<br>",
source, "<br>",
outcome_label1, "<br>",
Outcome_value1, "<br>",
date, "<br>"
))) +
theme_minimal() +
xlab('Date')+
labs(color='Source') +
ylab('COVID-19 activity (scaled to 100)')+
scale_color_manual(values=pal1) +
ggtitle(input$state.select2)
ggplotly(covid_ts_comp,tooltip='text')
})
#epic ED by age
output$distPlotcovid_epic_ED_age <- renderPlotly({
if(input$scale.covid==F){
covid_epic_ts_comp <- epic_ed_combo %>%
filter(geography==input$state.select3.covid & date >=as.Date('2023-07-01') & outcome_name=='COVID' & age_level !='Total') %>%
ggplot()+
geom_line(aes(x=date, y=Outcome_value2, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab('Percent of ED visits for covid (Epic Cosmos)')+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for COVID-19 in ',input$state.select3))
ggplotly(covid_epic_ts_comp)
}else{
covid_epic_ts_comp <- epic_ed_combo %>%
filter(geography==input$state.select3 & date >=as.Date('2023-07-01') & outcome_name=='COVID' & age_level !='Total') %>%
ggplot()+
geom_line(aes(x=date, y=Outcome_value3, group_by=age_level, color=age_level)) +
theme_minimal()+
xlab('Date')+
ylab('Rescaled ED visits for COVID-19 (Epic Cosmos)')+
scale_colour_viridis_d() +
ggtitle(paste0('ED visits for COVID-19 in ',input$state.select3))
ggplotly(covid_epic_ts_comp)
}
})
output$epicMapcovid <- renderPlotly({
map_data <- epic_ed_combo %>%
filter(date == input$selected_date.covid & age_level == 'Total' & outcome_name=='COVID') %>%
mutate(state = state.abb[match(geography, state.name)] ,
#Note, if >10%, cap at 10 for plotting!
Outcome_value2 = if_else(Outcome_value2>10,10, Outcome_value2)
#Outcome_value2 = if_else(Outcome_value4<5, Outcome_value4*0.01 ,Outcome_value2) #deals with cell suppression
) %>%
filter(!is.na(state)) %>%
as.data.frame()
max.val <- max(epic_ed_combo$Outcome_value2, na.rm=T)
pal1 <- viridis_pal()(4)
date.print <- input$selected_date.covid
p1 <- usmap::plot_usmap(regions = "state", data = map_data, values = "Outcome_value2") +
scale_fill_gradientn(
colors = pal1,
values = scales::rescale(c(0, 2.5, 5, 7.5, 10)),
limits = c(0, 10),
na.value = "#440154FF"
) +
ggtitle(paste("COVID-19 ED Visit Percentage all ages", date.print))
ggplotly(p1)
})
```
::: panel-tabset
#### Overall Trends
```{r}
selectInput("state.select2.covid", "State:",
choices=unique(epic_ed_combo$geography), selected='New York')
```
```{r}
#| panel: fill
plotlyOutput("distPlotcovid_dwh")
```
| |
|------------------------------------------------------------------------|
| Viral levels in the community can be measured in different ways, which is important because no measure is perfect. By triangulating data from sources like emergency department (ED) visits, hospitalizations, and wastewater surveillance, we can get a more complete picture of how and when a virus is spreading, which can help you make better-informed decisions. Epic data come from the [Epic Cosmos platform](https://www.epicresearch.org/about-us). Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/dwh_combined_plot1_long.csv). |
\#### Trends in positive tests
#### By age
```{r}
selectInput("state.select3.covid", "State:",
choices=state.name, selected='New York')
checkboxInput("scale.covid", "Rescale?",
value=T)
```
```{r}
#| panel: fill
plotlyOutput("distPlotcovid_epic_ED_age")
```
Data are smoothed with a 3 week average for vizualization.
#### Map of ED visits (state)
```{r}
sliderInput("selected_date.covid", label=NULL,
min = min(epic_ed_combo$date),
max = max(epic_ed_combo$date),
value = as.Date('2024-10-19'),
step=7,
timeFormat = "%Y-%m-%d",
animate = animationOptions(interval = 1000, loop = TRUE, playButton = 'P',pauseButton = 'S'))
```
```{r}
#| panel: fill
plotlyOutput("epicMapcovid")
```
Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/epic_ed_combo_rsv_flu_covid.csv).
#### Map of ED visits (county)
```{r}
#| panel: fill
subtitle= 'National Syndromic Surveillance Program (CDC)'
scaletitle= 'Percent'
pal1 <- viridis::viridis_pal()(4)
dates <- seq.Date(from=as.Date('2022-10-01'), to=Sys.Date(),by='week')
p1 <- rsv_flu_covid_county_filled_nssp %>%
filter(week_end==max(week_end)) %>%
mutate(percent_visits_covid=if_else(percent_visits_covid>3,3,percent_visits_covid)) %>%
usmap::plot_usmap(regions='county', data=.,values='percent_visits_covid',
color = NA, # Faint border color
size = 0 )+ # Thin border lines) +
theme(panel.background = element_rect(color = "white", fill = "white")) +
scale_fill_gradientn(
scaletitle,
colors = pal1,
values = scales::rescale(c(0, 0.75, 1.5, 2.25, 3)),
limits = c(0, 3),
na.value = "darkgray"
)
plotly::ggplotly(p1)%>%
layout(title = list(text = paste0(paste0('COVID-19 ED visits by jurisdiction ', max(rsv_flu_covid_county_filled_nssp$week_end)),
'<br>',
'<sup>',
subtitle,'</sup>')))
```
The maps shows the percentage of ED visits in each jurisdiction caused by COVID-19 Some states have county-level data available, while others have state-level data only. This includes data aggregated across all age groups. Ideally this would be broken out separately for infants and older adults. The data come from the national syndromic surveillance network. Get the data [here](https://github.com/ysph-dsde/DSDE-PopHIVE/raw/refs/heads/main/Data/plot_files/rsv_county_filled_map_nssp.csv).
:::
### Pneumococcus
*Pneumococcus is an important bacterial pathogen that causes severe disease like meningitis, blood-stream infections, and pneumonia. It also is a major cause of ear infections in children. Vaccines (PCVs) have been in use in the USA since 2000, with a switch to a new PCV that covered more strains in 2010. The introduction of these vaccines has largely led to the elimination of vaccine-targeted serotypes and smaller increases in disease caused by other serotypes. Some vaccine-targeted serotypes have recently re-emerged (e.g., 19F) for reasons that are still not clear.*
```{r pneumococcus_data}
#| context: data
#| include: false
#| cache: true
#| cache.extra: !expr file.info("data.csv")$mtime
ipd_serotype_age <- read_csv(paste0(url_files,'ipd_serotype_age_year.csv'))
all.sts <- unique(ipd_serotype_age$st)
ipd_serotype_state <- read_csv(paste0(url_files,'ipd_serotype_state_pct.csv'))
```
```{r pneumococcus_plots}
#| context: server
#Pneumococcal disease
output$stPlot <- renderPlotly({
p1 <- ipd_serotype_age %>%
filter(st %in% c(input$select.st)) %>%
ggplot(aes(x=year, y=N_IPD))+
geom_line()+
facet_wrap(~agec2, scales ='free', nrow=1) +
theme_classic()+
theme(axis.text.x = element_text(angle = 45, vjust = 1.0, hjust=1)) +
geom_vline(xintercept=c(1999.5, 2009.5), lty=2, color='gray')+
ylim(0,NA) +
ggtitle(paste0('Trends in IPD caused by serotype ', input$select.st, ' in the US'))
ggplotly(p1)
})
#serotype geography
output$stGeographyPlot <- renderPlotly({
ipd_serotype_state %>%
filter(sero==input$select.st2 ) %>%
ggplot( aes(fill=State, y=pct, x=sero)) +
geom_bar(position="dodge", stat="identity")+
scale_fill_viridis_d()+
theme_minimal()+
ylab('Proportion of IPD cases in the state') +
ggtitle(input$select.st2)
})
```
::: panel-tabset
#### Trends in serotype frequency
```{r}
selectInput("select.st",
"Select serotype:",
all.sts,
selected='19F')
```
```{r}
#| panel: fill
plotlyOutput("stPlot")
```
This shows trends in Invasive Pneumococcal Disease caused by different serotypes, as reported to the Active Bacterial Core Surevillance system (ABCs) at CDC. This is a network of 10 sites around the US.
#### Change in Invasive pneumococcal Disease 1998-2023
```{r pneumococcus_data_2}
#| include: false
pcv7 <- c('4','6B','9V','14','18C','19F','23F')
pcv10gsk <- c(pcv7,'1','5','7F')
pcv13 <- c(pcv7, '1','3','5','6A','7F','19A')
s1 <- readRDS(url('https://github.com/ysph-dsde/PopHIVE_DataHub/raw/refs/heads/main/Data/Pulled%20Data/pneumococcus/ABCs_st_1998_2023.rds')) %>%
rename(agec = "Age.Group..years.",
year=Year,
st=IPD.Serotype,
N_IPD = Frequency.Count) %>%
mutate( st= if_else(st=='16','16F', st)) %>%
group_by(st, year) %>%
summarize(N_IPD=sum(N_IPD)) %>%
ungroup() %>%
group_by(st) %>%
mutate(cum_N= sum(N_IPD)) %>%
filter(cum_N>100) %>%
ungroup() %>%
mutate(pcv13st = if_else(st %in% pcv13,'VT','NVT'))
s2_pre<- s1 %>%
filter(year %in% c(1998, 1999)) %>%
group_by(st, year) %>%
summarize(N_IPD=sum(N_IPD)) %>%
ungroup() %>%
group_by(st) %>%
summarize(N_IPD_pre=mean(N_IPD)) %>%
ungroup() %>%
tidyr::complete(st, fill=list(N_IPD_pre=0)) #fills 0
s2_pre13<- s1 %>%
filter(year %in% c(2008, 2009)) %>%
group_by(st, year) %>%
summarize(N_IPD=sum(N_IPD)) %>%
ungroup() %>%
group_by(st) %>%
summarize(N_IPD_pre=mean(N_IPD)) %>%
ungroup() %>%
tidyr::complete(st, fill=list(N_IPD_pre=0)) #fills 0
s2<- s1 %>%
group_by(st, year) %>%
summarize(N_IPD=sum(N_IPD)) %>% #sum across age group
ungroup() %>%
tidyr::complete(st, year, fill=list(N_IPD=0))%>% #fills 0
left_join(s2_pre, by='st') %>%
mutate(N_IPD_pre = if_else(is.na(N_IPD_pre),0, N_IPD_pre) ,
logRR = log((N_IPD+1)/(N_IPD_pre+1) ))
max_RR <- s2 %>%