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.
nynj_data <-filter(tuition_data, State == "New Jersey" | State == "New York")
ggplot(nynj_data, mapping = aes(x = year, y = tuition, color = State, group = State)) +
geom_line() +
geom_point() +
annotate("text", label = "New York", x = 2004.5, y = nynj_data[[13,3]] + 60) +
annotate("text", label = "New Jersey", x = 2004.5, y = nynj_data[[1,3]] + 60) +
labs(x = "Year", y = "Average tuition (in USD)",
title = "College Tuition in New York and New Jersey State") +
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?
Try to reproduce the following graph:
ggplot(tuition_data) +
stat_summary(aes(x = tuition, y = State, color = State),
fill = "black", fun = "mean", geom = "bar") +
labs(title = 'Year: {frame_time}', x = 'tuition (in USD)', y = 'State') +
transition_time(year) +
theme(legend.position = "none") +
ease_aes('linear') -> p
animate(p, duration = 6, fps = 2)
Try to reproduce the following graph with the diamonds data set:
ggplot(diamonds) +
geom_point(aes(x = carat, y = price, color = color)) +
geom_smooth(aes(x = carat, y = price)) +
labs(title = "Cut Quality: {closest_state}", x = "Carat", y = "Price (USD)") +
theme(plot.title = element_text(hjust = 0.5)) +
enter_fade() + exit_shrink() +
transition_states(cut) -> p2
animate(p2, duration = 15, fps = 10)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'