Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###################################################################################################
- # Tate Art Museum - The aspect ratio of an art collection.
- # Created by: reddit.com/user/brianhaas19
- # Link to data
- # https://github.com/rfordatascience/tidytuesday/tree/master/data/2021/2021-01-12
- # Setup
- ### Libraries:
- library(tidyverse)
- library(ggExtra)
- theme_set(theme_bw())
- ### Colors:
- blue <- "steelblue"
- # Load data
- ### Raw data:
- artwork <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-12/artwork.csv')
- # Clean data
- ### Mainly just removing variables with too much missing data:
- artwork <- artwork %>%
- select(-thumbnailCopyright, -depth, -inscription, -thumbnailUrl) # too much missing data
- # Fix an incorrect height which causes an outlier when calculating aspect ratio:
- artwork[(artwork$id == 93796), "width"] <- 2400
- artwork[(artwork$id == 93796), "height"] <- 3600
- # Visualize
- # Suggested parameters for R notebook: fig.height=9, fig.width=12
- gr <- (1 + sqrt(5))/2 # Golden ratio
- p1 <- artwork %>%
- filter(!is.na(width), !is.na(height), !is.na(year)) %>%
- mutate(aspect_ratio = height/width) %>%
- filter(year >= 1775, aspect_ratio < 2, aspect_ratio > 0.5) %>%
- ggplot(aes(year, aspect_ratio)) +
- geom_point(color = blue, size = 0.5, alpha = 0.2) +
- scale_x_continuous(breaks = seq(1700, 2000, 50)) +
- scale_y_continuous(breaks = round(c(1/gr, 2/3, 5/7, 3/4, 4/5, 5/6, 1, 6/5, 5/4, 4/3, 7/5, 3/2, gr), 2),
- labels = c(expression(1/phi), '2/3', '5/7', '3/4', '4/5', '5/6', 1, '6/5', '5/4', '4/3', '7/5', '3/2', expression("Golden ratio: "*phi)),
- expand = c(0, 0),
- sec.axis = sec_axis(trans = ~.*1, name = NULL,
- breaks = round(c(1/gr, 2/3, 5/7, 3/4, 4/5, 5/6, 1, 6/5, 5/4, 4/3, 7/5, 3/2, gr), 2),
- labels = c(expression(1/phi), '2/3', '5/7', '3/4', '4/5', '5/6', 1, '6/5', '5/4', '4/3', '7/5', '3/2', expression(phi)))) +
- labs(x = "Year", y = "Aspect Ratio",
- title = expression(paste(bold("Tate Art Museum"), " - The aspect ratio of an art collection.")),
- subtitle = "The aspect ratio - calculated as height/width - of 58,992 works of art in the Tate Art Museum plotted over time.",
- caption = expression(paste("Created by: ", italic("reddit.com/user/brianhaas19"), "\tData source: ", italic("https://github.com/rfordatascience/tidytuesday/tree/master/data/2021/2021-01-12")))) +
- theme(plot.title = element_text(vjust = -1), # shift it down a bit
- plot.subtitle = element_text(vjust = -1), # shift it down a bit
- plot.caption = element_text(hjust = 0),
- panel.grid.minor = element_blank())
- P <- ggMarginal(p1, type = "histogram", size = 8,
- xparams = list(binwidth = 5), yparams = list(binwidth = 0.05),
- fill = blue, color = "white")
- P
- ### Uncomment to save to disk:
- # ggsave(plot = P,
- # filename = "tate_aspect_ratio.png",
- # width = 12, height = 9)
- ###################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement