I have variables from a list (year, class size, and tuition) that I would like to join in a table and then create a time series plot using year and class size. However, when I use ggplot, an error says it doesn't know how to deal with list data. Here's my code:
univ.ann <- results1[c(as.character(1996:2015))]
size <- sapply(univ.ann, function(LIST) LIST$student$size) %>%
unlist()
size_df <- data.frame(classsize = size) %>%
rownames_to_column(var = "year")
tuition <- sapply(univ.ann, function(LIST) LIST$cost$tuition$in_state) %>%
unlist()
tuition_df <- data.frame(in_state = tuition) %>%
rownames_to_column(var = "year")
full_join(size_df, tuition_df, by = c("year" = "year")) %>%
arrange(year)
Everything at this point works, however, a plot fails to show up when I execute the following code chunk:
university_plot <- ggplot(univ.ann, aes(year)) +
geom_point(aes(y=size_df)) +
ylab("Size") +
xlab("Year") +
ggtitle("Class Size Plot")
university_plot
Is there a way to use ggplot for list variables?