|
1 | 1 | --- |
2 | | -title: "Get started with `epidatr`" |
3 | | -output: rmarkdown::html_vignette |
| 2 | +title: "Get started with epidatr" |
| 3 | +output: |
| 4 | + rmarkdown::html_vignette: |
| 5 | + code_folding: show |
4 | 6 | vignette: > |
5 | | - %\VignetteIndexEntry{Get started with `epidatr`} |
| 7 | + %\VignetteIndexEntry{Get started with epidatr} |
6 | 8 | %\VignetteEngine{knitr::rmarkdown} |
7 | 9 | %\VignetteDepends{ggplot2} |
8 | 10 | \usepackage[utf8]{inputenc} |
@@ -187,6 +189,51 @@ ggplot(epidata, aes(x = time_value, y = value)) + |
187 | 189 | ) |
188 | 190 | ``` |
189 | 191 |
|
| 192 | +`ggplot2` can also be used to [create choropleths](https://r-graphics.org/recipe-miscgraph-choropleth). |
| 193 | + |
| 194 | + |
| 195 | +```{r class.source = "fold-hide", out.height="65%"} |
| 196 | +library(maps) |
| 197 | +
|
| 198 | +# Obtain the most up-to-date version of the smoothed covid-like illness (CLI) |
| 199 | +# signal from the COVID-19 Trends and Impact survey for all states on a single day |
| 200 | +cli_states <- pub_covidcast( |
| 201 | + source = "fb-survey", |
| 202 | + signals = "smoothed_cli", |
| 203 | + geo_type = "state", |
| 204 | + time_type = "day", |
| 205 | + geo_values = "*", |
| 206 | + time_values = 20210410 |
| 207 | +) |
| 208 | +
|
| 209 | +# Get a mapping of states to longitude/latitude coordinates |
| 210 | +states_map <- map_data("state") |
| 211 | +
|
| 212 | +# Convert state abbreviations into state names |
| 213 | +cli_states <- mutate( |
| 214 | + cli_states, state = ifelse( |
| 215 | + geo_value == "dc", |
| 216 | + "district of columbia", |
| 217 | + state.name[match(geo_value, tolower(state.abb))] %>% tolower() |
| 218 | + ) |
| 219 | +) |
| 220 | +
|
| 221 | +# Add coordinates for each state |
| 222 | +cli_states <- left_join(states_map, cli_states, by = c("region" = "state")) |
| 223 | +
|
| 224 | +# Plot |
| 225 | +ggplot(cli_states, aes(x = long, y = lat, group = group, fill = value)) + |
| 226 | + geom_polygon(colour = "black", linewidth = 0.2) + |
| 227 | + coord_map("polyconic") + |
| 228 | + labs( |
| 229 | + title = "Smoothed CLI from Facebook Survey", |
| 230 | + subtitle = "All states, 2021-04-10", |
| 231 | + x = "Longitude", |
| 232 | + y = "Latitude" |
| 233 | + ) |
| 234 | +``` |
| 235 | + |
| 236 | + |
190 | 237 | ## Finding locations of interest |
191 | 238 |
|
192 | 239 | Most data is only available for the US. Select endpoints report other countries at the national and/or regional levels. Endpoint descriptions explicitly state when they cover non-US locations. |
|
0 commit comments