-
Notifications
You must be signed in to change notification settings - Fork 3
/
report_with_jquery.rmd
167 lines (100 loc) · 3.44 KB
/
report_with_jquery.rmd
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
<head>
<meta charset="utf-8">
<title>Reported Active Tuberculosis Cases in the United States, 1993-2013</title>
<link rel="stylesheet" href="jquery-ui/jquery-ui.min.css">
<script src="jquery-ui/external/jquery/jquery.js"></script>
<script src="jquery-ui/jquery-ui.js"></script>
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
</head>
```{r setup, echo= FALSE, message=FALSE,warning= FALSE}
# Strings ain't factors
options(stringsAsFactors = FALSE)
# Load the required libraries
library(knitr)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
# Set the default ggplot theme
theme_set(theme_bw())
# Set default chunk options
opts_chunk$set(echo = FALSE,
results = 'asis',
message = FALSE,
warning = FALSE,
error = TRUE)
# Read in the table
tbstats_raw <- read.delim("cdc_otis_extract.txt")
tbstats <- tbstats_raw %>%
filter(Notes == "") %>%
mutate(per.complete = as.numeric(gsub(x = Percent.of.Completion.of.Therapy.Within.One.Year.Among.Those.Eligible,
pattern = "%|Not Applicable",
replacement = ""))) %>%
select(-matches("Notes"), -ends_with(".Code"))
```
# Reported Active Tuberculosis Cases in the United States: 1993-2013
<div id="tabs">
<ul>
<li><a href="#nation">Nationally</a></li>
<li><a href="#states">By State</a></li>
<li><a href="#treatment">Treatment Completion</a></li>
</ul>
<div id="nation">
## Reported Active TB Cases in the United States, 1993-2013
```{r nation}
tbstats %>%
group_by(Year) %>%
summarise(n_cases = sum(Count)) %>%
ggplot(aes(x = Year, y = n_cases)) +
geom_line(size = 2) +
labs(x = "Year Reported",
y = "Number of Cases",
title = "Reported Active TB Cases in the United States") +
expand_limits(y = 0)
```
</div>
<div id="states">
## Reported Active TB Cases by State
```{r cases}
top_five <-
tbstats %>%
filter(Year == 1993) %>%
arrange(desc(Count)) %>%
slice(1:5) %>%
select(State)
tbstats$top_five_state <- factor(tbstats$State, levels = c(top_five$State, "Other"))
tbstats$top_five_state[is.na(tbstats$top_five_state)] <- "Other"
tbstats %>%
group_by(Year, State) %>%
summarise(n_cases = sum(Count),
top_five_state = unique(top_five_state)) %>%
ggplot(aes(x = Year, y = n_cases, group = State)) +
geom_line(aes(color = top_five_state, size = top_five_state)) +
scale_size_manual(values = c(rep(2, 5), 0.5)) +
scale_color_manual(values = c(brewer.pal(n = 5, "Paired"), "grey")) +
labs(x = "Year Reported",
y = "Number of Cases",
color = "State",
title = "Reported Active TB Cases in the United States") +
expand_limits(y = 0)
```
</div>
<div id="treatment">
## Treatment Completion Within One Year for Eligible US TB Cases
```{r tx_completion}
tbstats %>%
group_by(Year) %>%
summarise(tx_completion = weighted.mean(per.complete, w = Count)) %>%
ggplot(aes(x = Year, y = tx_completion)) +
geom_line(size = 2) +
expand_limits(y = 0) +
labs(x = "Year Reported",
y = "Percent of Cases Completed",
title = "Completion of Treatment within One Year for Eligible Cases")
```
</div>
</div>
Data downloaded from the [CDC WONDER query tool](http://wonder.cdc.gov/tb.html).