tidyTuesday

This week’s is on national parks. Very neat data.

The webpage shows how to get and load the data. I will use two packages; one for themes and one for animation.

library(tidyverse)
## -- Attaching packages ------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   0.8.3     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ---------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggthemes)
options(scipen=6)
park_visits <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-09-17/national_parks.csv")
## Parsed with column specification:
## cols(
##   year = col_character(),
##   gnis_id = col_character(),
##   geometry = col_character(),
##   metadata = col_character(),
##   number_of_records = col_double(),
##   parkname = col_character(),
##   region = col_character(),
##   state = col_character(),
##   unit_code = col_character(),
##   unit_name = col_character(),
##   unit_type = col_character(),
##   visitors = col_double()
## )
park_visits %>% filter(unit_code=="CRLA" & year!="Total") %>% mutate(NYear = as.numeric(year)) %>% ggplot(., aes(x=NYear,y=visitors)) + geom_line(color="hotpink") + labs(x="Year", y="Visitors", main="Visitors to Crater Lake National Park") + theme_economist_white()

An Animation

gganimate is really neat.

library(gganimate)
park_visits %>% filter(unit_code=="CRLA" & year!="Total") %>% mutate(NYear = as.numeric(year)) %>% ggplot(., aes(x=NYear,y=visitors)) + geom_line(color="hotpink") + labs(x="Year", y="Visitors", title="Visitors to Crater Lake National Park") + theme_economist_white() + transition_reveal(NYear)