Skip to content

Commit 1f42de6

Browse files
committed
Remove manual class() calls in old blog posts
These can be replaced with as.covidcast_signal, which is much clearer.
1 parent 465a994 commit 1f42de6

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

content/blog/2020-08-26-fb-survey.Rmd

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,23 @@ df_in = covidcast_signal("jhu-csse", "confirmed_7dav_incidence_prop",
149149
df_fb_avg = df_fb %>% group_by(geo_value) %>% summarize(value = mean(value))
150150
df_in_avg = df_in %>% group_by(geo_value) %>% summarize(value = mean(value))
151151
152-
# Set a bunch of fields so that the data frames know how to plot themselves
153-
df_fb_avg$time_value = df_in_avg$time_value = start_day
154-
df_fb_avg$issue = df_in_avg$issue = start_day
155-
attributes(df_fb_avg)$metadata$geo_type = "state"
156-
attributes(df_in_avg)$metadata$geo_type = "state"
157-
class(df_fb_avg) = c("covidcast_signal", class(df_fb_avg))
158-
class(df_in_avg) = c("covidcast_signal", class(df_in_avg))
152+
# Turn these into covidcast_signal data frames that can be mapped
153+
df_fb_avg = df_fb_avg %>%
154+
mutate(time_value = start_day) %>%
155+
as.covidcast_signal(signal = "fb_avg", geo_type = "state")
156+
157+
df_in_avg = df_in_avg %>%
158+
mutate(time_value = start_day) %>%
159+
as.covidcast_signal(signal = "in_avg", geo_type = "state")
159160
160161
# Plot choropleth maps, using the covidcast plotting functionality
161162
subtitle = paste("Averaged over", start_day, "to", end_day)
162163
p1 = plot(df_fb_avg,
163164
title = "% of people with COVID symptoms, based on Facebook surveys",
164-
range=c(0, 1), choro_params = list(subtitle = subtitle))
165+
range = c(0, 1), choro_params = list(subtitle = subtitle))
165166
p2 = plot(df_in_avg,
166167
title = "Daily new confirmed COVID-19 cases per 100,000 people",
167-
range=c(0, 30), choro_params = list(subtitle = subtitle))
168+
range = c(0, 30), choro_params = list(subtitle = subtitle))
168169
grid.arrange(p1, p2, nrow = 1)
169170
```
170171

@@ -539,12 +540,13 @@ or we didn't have enough data from the surveys in
539540
order to estimate % CLI and % CLI-in-community signals there.
540541

541542
```{r, fig.width = 10, fig.height = 4, out.extra = 'class="wide-figure"'}
542-
# Set a bunch of fields so that the data frames know how to plot themselves
543-
df_cor1$time_value = df_cor2$time_value = start_day
544-
df_cor1$issue = df_cor2$issue = start_day
545-
attributes(df_cor1)$metadata$geo_type = "county"
546-
attributes(df_cor2)$metadata$geo_type = "county"
547-
class(df_cor1) = class(df_cor2) = c("covidcast_signal", "data.frame")
543+
# Use as.covidcast_signal to turn these into mappable signals
544+
df_cor1 = df_cor1 %>%
545+
mutate(time_value = start_day) %>%
546+
as.covidcast_signal(signal = "cor1")
547+
df_cor2 = df_cor2 %>%
548+
mutate(time_value = start_day) %>%
549+
as.covidcast_signal(signal = "cor1")
548550
549551
# Plot choropleth maps, using the covidcast plotting functionality
550552
p1 = plot(df_cor1, title = "Correlation between % CLI and case rates",

content/blog/2020-10-14-dv-signal.Rmd

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ df_in = covidcast_signal("usa-facts", "confirmed_7dav_incidence_prop",
8989
df_dv_avg = df_dv %>% group_by(geo_value) %>% summarize(value = mean(value))
9090
df_in_avg = df_in %>% group_by(geo_value) %>% summarize(value = mean(value))
9191
92-
# Set a bunch of fields so that the data frames know how to plot themselves
93-
df_dv_avg$time_value = df_in_avg$time_value = start_day
94-
df_dv_avg$issue = df_in_avg$issue = start_day
95-
attributes(df_dv_avg)$metadata$geo_type = "state"
96-
attributes(df_in_avg)$metadata$geo_type = "state"
97-
class(df_dv_avg) = c("covidcast_signal", class(df_dv_avg))
98-
class(df_in_avg) = c("covidcast_signal", class(df_in_avg))
92+
# Use as.covidcast_signal to turn these into covidcast data frames
93+
df_dv_avg <- df_dv_avg %>%
94+
mutate(time_value = start_day) %>%
95+
as.covidcast_signal(signal = "dv_avg", geo_type = "state")
96+
df_in_avg <- df_in_avg %>%
97+
mutate(time_value = start_day) %>%
98+
as.covidcast_signal(signal = "in_avg", geo_type = "state")
9999
100100
# Plot choropleth maps, using the covidcast plotting functionality
101101
subtitle = paste("Averaged over", start_day, "to", end_day)
@@ -337,8 +337,12 @@ lm_dv_cases_df = dv_cases_df %>%
337337
ungroup()
338338
339339
df_cor_by_time_adj = covidcast_cor(
340-
dv_cases_df %>% mutate(value = dv*slope_6wk + int_6wk, issue = time_value),
341-
dv_cases_df %>% mutate(value = cases, issue = time_value),
340+
dv_cases_df %>%
341+
mutate(value = dv*slope_6wk + int_6wk, issue = time_value) %>%
342+
as.covidcast_signal(signal = "dv_cases"),
343+
dv_cases_df %>%
344+
mutate(value = cases, issue = time_value) %>%
345+
as.covidcast_signal(signal = "dv_cases"),
342346
by = "time_value",
343347
method = "spearman")
344348

0 commit comments

Comments
 (0)