Add the data of New Jersey (including a new annotation) to the same
plot so that the graph shows evolution of college tuition in New York
and New Jersey in the same plot.
read_csv("/Users/yuhe/Downloads/us_avg_tuition.csv") -> tuition_data
## Rows: 50 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (13): State, 2004-05, 2005-06, 2006-07, 2007-08, 2008-09, 2009-10, 2010-...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
tuition_data <- tuition_data %>%
pivot_longer(cols = 2:13, names_to = "year", values_to = "tuition") %>%
mutate(tuition = parse_number(tuition)) %>%
tidyr::extract(year, into = "year", "^(....)") %>%
mutate(year = as.numeric(year))
nyj_data <- filter(tuition_data, State == "New Jersey" | State == "New York")
ggplot(nyj_data, aes(x = year, y = tuition, color = State, group = State)) +
geom_line() +
geom_point() +
labs(x = "Year", y = "Average tuition (in USD)", title = "College Tuition in New York and New Jersey") +
xlim(2003.5, 2015.5) + theme(plot.title = element_text(hjust = 0.5)) +
scale_x_continuous(breaks = seq(2004, 2015, by = 1)) +
transition_reveal(year)
## Scale for x is already present.
## Adding another scale for x, which will replace the existing scale.
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
