Skip to content

Commit 26b13ee

Browse files
Refactor some more common code
1 parent 8e5af40 commit 26b13ee

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

R-notebooks/dashboard_functions.R

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
plot_28_day_frequency <- function(df_to_plot, geo_type) {
2-
# These are all required for rendering using covidcast.plot
3-
df_to_plot$time_value = "2020-04-15"
4-
df_to_plot$issue = "2020-04-15"
5-
attributes(df_to_plot)$geo_type = geo_type
6-
class(df_to_plot) = c("covidcast_signal", "data.frame")
7-
8-
plot(df_to_plot, range=c(0,28))
9-
}
1+
make_covidcast_signal <- function(destination, source, geo_type) {
2+
destination$time_value = source$time_value[1]
3+
destination$issue = source$issue[1]
4+
attributes(destination)$geo_type = geo_type
5+
class(destination) = c("covidcast_signal", "data.frame")
6+
return(destination)
7+
}
8+
9+
plot_28_day_frequency_state <- function(df_to_plot) {
10+
states_present = df_to_plot %>%
11+
group_by(geo_value) %>%
12+
summarize(value = n())
13+
14+
covidcast_signal_to_plot = make_covidcast_signal(states_present, df_to_plot, "state")
15+
16+
plot(covidcast_signal_to_plot, range=c(0,28))
17+
}
18+
19+
plot_28_day_frequency_county <- function(df_to_plot) {
20+
counties_present = df_to_plot %>%
21+
group_by(geo_value) %>%
22+
summarize(value = n()) %>% ungroup() %>%
23+
filter(substr(geo_value, 3, 5) != "000")
24+
25+
covidcast_signal_to_plot = make_covidcast_signal(counties_present, df_to_plot, "county")
26+
27+
plot(covidcast_signal_to_plot, range=c(0,28))
28+
}

R-notebooks/doctor_visits_dashboard.Rmd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ This visualizes the county coverage -- how frequently does each county show up i
5454

5555
```{r, fig.width = 10, fig.height = 8}
5656
57-
counties_present = df_doctor_visits_counties %>%
58-
group_by(geo_value) %>%
59-
summarize(value = n()) %>% ungroup() %>%
60-
filter(substr(geo_value, 3, 5) != "000")
61-
6257
source("dashboard_functions.R")
63-
plot_28_day_frequency(counties_present, "county")
58+
plot_28_day_frequency_county(df_doctor_visits_counties)
6459
```

R-notebooks/ght_dashboard.Rmd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ This visualizes the state coverage -- how frequently does each state show up in
8383

8484
```{r, fig.width = 10, fig.height = 8}
8585
86-
states_present = df_ght_states %>%
87-
group_by(geo_value) %>%
88-
summarize(value = n())
89-
9086
source("dashboard_functions.R")
91-
plot_28_day_frequency(states_present, "state")
87+
plot_28_day_frequency_state(df_ght_states)
9288
```

R-notebooks/hospital_admissions_dashboard.Rmd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ This visualizes the county coverage -- how frequently does each county show up i
6161

6262
```{r, fig.width = 10, fig.height = 8}
6363
64-
counties_present = df_hospital_admissions_counties %>%
65-
group_by(geo_value) %>%
66-
summarize(value = n()) %>% ungroup() %>%
67-
filter(substr(geo_value, 3, 5) != "000")
68-
6964
source("dashboard_functions.R")
70-
plot_28_day_frequency(counties_present, "county")
65+
plot_28_day_frequency_county(df_hospital_admissions_counties)
7166
```

R-notebooks/quidel_dashboard.Rmd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ This visualizes the state coverage -- how frequently does each state show up in
8383

8484
```{r, fig.width = 10, fig.height = 8}
8585
86-
states_present = df_quidel_states %>%
87-
group_by(geo_value) %>%
88-
summarize(value = n())
89-
9086
source("dashboard_functions.R")
91-
plot_28_day_frequency(states_present, "state")
87+
plot_28_day_frequency_state(df_quidel_states)
9288
```

0 commit comments

Comments
 (0)