Skip to content

Commit a1a6af2

Browse files
committed
Fix US region plot rendering
1 parent ff7924a commit a1a6af2

File tree

3 files changed

+740
-764
lines changed

3 files changed

+740
-764
lines changed

content/blog/2021-01-22-holiday-surveys.Rmd

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ from airlines suggested that travel reached its highest levels since the start
6767
of the pandemic during the Christmas holiday with about 1% of the US population
6868
taking flights in just the few days surrounding the holiday.
6969

70-
```{r traveled-recently, message=FALSE, fig.width=10, out.extra = 'class="wide-figure"'}
70+
```{r traveled-recently, message=FALSE, fig.width=9, out.extra = 'class="wide-figure"'}
7171
library(covidcast)
7272
library(ggplot2)
7373
library(stringr)
@@ -105,8 +105,8 @@ travel_normed <- travel %>%
105105
106106
regionmap <- travel %>%
107107
filter(geo_value %in% str_to_lower(statelist)) %>%
108-
mutate(value=plyr::mapvalues(geo_value, str_to_lower(statelist), regions),
109-
value=as.integer(factor(value)))
108+
mutate(value = plyr::mapvalues(geo_value, str_to_lower(statelist), regions),
109+
value = as.integer(factor(value)))
110110
111111
grid_label <- textGrob("Data from Delphi COVIDcast, delphi.cmu.edu",
112112
hjust = 1, x = 1, gp = gpar(fontsize = 9))
@@ -119,20 +119,22 @@ g1 <- travel_normed %>%
119119
linetype = "dashed", size = 1.5, color = "darkgrey") +
120120
geom_line(aes(x = date, y = mean, color = Region)) +
121121
geom_ribbon(aes(x = date, ymin = mean - se, ymax = mean + se, fill = Region),
122-
alpha=0.2) +
122+
alpha = 0.2) +
123123
scale_x_date(date_breaks = "2 weeks",
124124
date_labels = "%b %d %Y",
125125
date_minor_breaks = "1 week") +
126126
labs(x = "Date", y = "% Out-of-state travel in last 5 days",
127127
title = "Relative out-of-state travel by US region",
128128
subtitle = "From Delphi's surveys, conducted through Facebook") +
129129
theme_bw() +
130-
theme(legend.position = c(.075, .9)) +
130+
theme(legend.position = c(0.095, 0.8)) +
131131
guides(color = FALSE)
132132
133133
g2 <- plot(regionmap,
134-
title = "US Regions", range = c(1, 4),
135-
choro_col = c("#F8766D", "#7CAE00", "#00BFC4", "#C77CFF"))
134+
title = "US Regions",
135+
choro_col = c("#F8766D", "#7CAE00", "#00BFC4", "#C77CFF"),
136+
choro_params = list(breaks = c(1, 2, 3, 4))) +
137+
theme(legend.position = "none")
136138
137139
lay <- rbind(c(1,1,1,2),
138140
c(1,1,1,2))

content/blog/2021-01-22-holiday-surveys.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Home for the holidays? The impact of US holidays on social behaviors and preventative measures"
2+
title: "Home for the Holidays? The Impact of US Holidays on Social Behaviors and Preventative Measures"
33
author: "Leanna Morinishi, Kris Barkume, Esther Kim, and Alex Reinhart"
44
date: 2021-01-22
55
tags:
@@ -29,7 +29,8 @@
2929
toc: true
3030
---
3131

32-
<script src="/rmarkdown-libs/header-attrs/header-attrs.js"></script>
32+
<link href="/rmarkdown-libs/anchor-sections/anchor-sections.css" rel="stylesheet" />
33+
<script src="/rmarkdown-libs/anchor-sections/anchor-sections.js"></script>
3334

3435
<div id="TOC">
3536
<ul>
@@ -111,8 +112,8 @@ <h2>Travel and Other Social Behaviors During US Holidays</h2>
111112

112113
regionmap &lt;- travel %&gt;%
113114
filter(geo_value %in% str_to_lower(statelist)) %&gt;%
114-
mutate(value=plyr::mapvalues(geo_value, str_to_lower(statelist), regions),
115-
value=as.integer(factor(value)))
115+
mutate(value = plyr::mapvalues(geo_value, str_to_lower(statelist), regions),
116+
value = as.integer(factor(value)))
116117

117118
grid_label &lt;- textGrob(&quot;Data from Delphi COVIDcast, delphi.cmu.edu&quot;,
118119
hjust = 1, x = 1, gp = gpar(fontsize = 9))
@@ -125,25 +126,28 @@ <h2>Travel and Other Social Behaviors During US Holidays</h2>
125126
linetype = &quot;dashed&quot;, size = 1.5, color = &quot;darkgrey&quot;) +
126127
geom_line(aes(x = date, y = mean, color = Region)) +
127128
geom_ribbon(aes(x = date, ymin = mean - se, ymax = mean + se, fill = Region),
128-
alpha=0.2) +
129+
alpha = 0.2) +
129130
scale_x_date(date_breaks = &quot;2 weeks&quot;,
130131
date_labels = &quot;%b %d %Y&quot;,
131132
date_minor_breaks = &quot;1 week&quot;) +
132133
labs(x = &quot;Date&quot;, y = &quot;% Out-of-state travel in last 5 days&quot;,
133134
title = &quot;Relative out-of-state travel by US region&quot;,
134135
subtitle = &quot;From Delphi&#39;s surveys, conducted through Facebook&quot;) +
135136
theme_bw() +
136-
theme(legend.position = c(.075, .9)) +
137+
theme(legend.position = c(0.095, 0.8)) +
137138
guides(color = FALSE)
138139

139140
g2 &lt;- plot(regionmap,
140-
title = &quot;US Regions&quot;, range = c(1, 4),
141-
choro_col = c(&quot;#F8766D&quot;, &quot;#7CAE00&quot;, &quot;#00BFC4&quot;, &quot;#C77CFF&quot;))
141+
title = &quot;US Regions&quot;,
142+
choro_col = c(&quot;#F8766D&quot;, &quot;#7CAE00&quot;, &quot;#00BFC4&quot;, &quot;#C77CFF&quot;),
143+
choro_params = list(breaks = c(1, 2, 3, 4),
144+
legend_position = &quot;none&quot;)) +
145+
theme(legend.position = &quot;none&quot;)
142146

143147
lay &lt;- rbind(c(1,1,1,2),
144148
c(1,1,1,2))
145149
grid.arrange(g1, g2, nrow = 1, bottom = grid_label, layout_matrix=lay)</code></pre>
146-
<p><img src="/blog/2021-01-22-holiday-surveys_files/figure-html/traveled-recently-1.svg" width="960" class="wide-figure" /></p>
150+
<p><img src="/blog/2021-01-22-holiday-surveys_files/figure-html/traveled-recently-1.svg" width="864" class="wide-figure" /></p>
147151
<p>In the COVID-19 survey, we see an increase in self-reported out-of-state travel
148152
in this time frame by surveyed adults. The figure above depicts the normalized
149153
percent of survey respondents who recently traveled out-of-state for 4 US

0 commit comments

Comments
 (0)