Push the knit button!
library(tidyverse) # contains ggplot2, dplyr, tidyr, etc
library(plotly)
Load the abs data with
load(here::here("data/abs.rda"))
Make an animation of Unemployed by Renting over time for the abs data.
a1 <- ggplot(abs, aes(
x=Unemployed,
y=Renting,
colour=State)) +
geom_point(aes(frame=year, #<<
ids=UniqueID)) + #<<
scale_colour_brewer("",
palette = "Dark2")
ggplotly(a1, width=500, height=500)
Compute the yearly average by state for each of the abs statistics. Make a linked multiple time series display of the four statistics.
abs_state <- abs %>%
group_by(year, State) %>%
summarise_at(vars(Mortgage:Unemployed),
mean, na.rm=TRUE, .groups="drop") %>%
pivot_longer("Mortgage":"Unemployed",
names_to ="Statistic",
values_to = "Percentage")
abs_key <- highlight_key(abs_state,
~State)
abs_p <- ggplot(abs_key,
aes(x=year,
y=Percentage)) +
geom_line(aes(group=State),
alpha=0.5) +
facet_wrap(~Statistic,
scales="free_y")
abs_gg <- ggplotly(abs_p,
height = 600,
width = 500)
highlight(abs_gg)