-
Notifications
You must be signed in to change notification settings - Fork 23
/
02-addendum.Rmd
75 lines (63 loc) · 2.1 KB
/
02-addendum.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
title: "Lab 02: Addendum"
subtitle: "CS631"
author: "Alison Hill"
output:
html_document:
theme: flatly
toc: TRUE
toc_float: TRUE
toc_depth: 2
number_sections: TRUE
---
```{r setup, include = FALSE, cache = FALSE}
knitr::opts_chunk$set(error = TRUE, comment = NA, warning = FALSE, errors = FALSE, message = FALSE, tidy = FALSE, cache = FALSE)
```
```{r}
library(tidyverse)
moma <- read_csv("http://bit.ly/cs631-moma")
moma_singles_summary <- moma %>%
filter(num_artists == 1) %>%
mutate(lag_acquired = year_acquired - year_created,
artist_gender = as.factor(artist_gender)) %>%
group_by(year_acquired, artist_gender) %>%
summarize(n_acquired = n(),
median_lag = median(lag_acquired)) %>%
complete(year_acquired, artist_gender,
fill = list(n_acquired = 0))
ggplot(moma_singles_summary, aes(x = year_acquired,
y = n_acquired,
color = artist_gender)) +
geom_point()
ggplot(moma_singles_summary, aes(x = year_acquired,
y = median_lag,
color = artist_gender,
group = artist_gender)) +
geom_point() +
geom_line()
```
Tag top artists
```{r}
top_artists <- moma %>%
count(artist_gender, artist, sort = TRUE) %>%
group_by(artist_gender) %>%
top_n(1) %>%
filter(!is.na(artist_gender)) %>%
pull(artist)
moma <- moma %>%
mutate(top_to_color = case_when(
artist %in% top_artists & artist_gender == "Male" ~ "Picasso",
artist %in% top_artists & artist_gender == "Female" ~ "Levine"
))
moma_top <- moma %>%
filter(!is.na(top_to_color))
moma_else <- moma %>%
filter(is.na(top_to_color))
# need to separate plotting of "NA" points
# plot Levine and Picasso points with separate geom layer
ggplot(data = NULL, aes(year_created, year_acquired)) +
geom_point(data = moma_else, color = "grey70", alpha = .5) +
geom_point(data = moma_top, aes(color = top_to_color), size = 2) +
labs(x = "Year Painted", y = "Year Acquired") +
ggtitle("MoMA Keeps Its Collection Current")
```