acquisitionsByDepartment.R (1728B)
1 # Just curious whether different departments have different acquisition activity 2 # over the years. 3 4 require(dplyr) 5 require(tidyr) 6 require(ggplot2) 7 8 # Ugh 9 rm(list=ls()) 10 artworks <- read.csv("Artworks.csv", stringsAsFactors = FALSE) 11 12 departments <- c("Painting & Sculpture", 13 "Drawings", 14 "Architecture & Design", 15 "Photography", 16 "Prints & Illustrated Books") 17 18 # Just pull out the year, since dates aren't always formatted correctly, and 19 # make Department a factor. 20 artworks <- artworks %>% 21 filter(grepl("[0-9]{4}", DateAcquired)) %>% 22 mutate(year_acquired = as.numeric(sub(".*([0-9]{4}).*", "\\1", DateAcquired)), 23 Department = ifelse(Department %in% departments, Department, "Other"), 24 Department = factor(Department, c("Other", departments))) 25 26 # Find the cumulative number of works from each department 27 artworks.tally <- artworks %>% 28 group_by(year_acquired, Department) %>% 29 tally() %>% 30 # Fill in missing years 31 spread(Department, n, fill = 0) %>% gather("Department", "n", -year_acquired) %>% 32 # Find the total works over time 33 group_by(Department) %>% 34 mutate(total_works=cumsum(n)) 35 36 p1 <- artworks.tally %>% 37 ggplot(aes(x=year_acquired, y=total_works, fill=Department)) + 38 geom_area(position="stack") + 39 theme_minimal() + 40 scale_fill_brewer(type="qual", palette = "Dark2") + 41 scale_x_continuous(breaks=round(seq(min(artworks$year_acquired), 42 max(artworks$year_acquired), 43 length.out = 5))) + 44 labs(title = "MoMA's cumulative works by time", 45 y = "Total works", 46 x = "Year acquired") 47 print(p1) 48 ggsave("cumulative_works.png")