-
Notifications
You must be signed in to change notification settings - Fork 0
/
2021-03-02_Superbowl-Ads.Rmd
119 lines (110 loc) · 4.94 KB
/
2021-03-02_Superbowl-Ads.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
title: "2021-03-02-Superbowl_Ads"
author: "Kristen A, kkakey"
date: "3/5/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(ggtext)
youtube <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-03-02/youtube.csv')
```
```{r}
# view count
# of the top 30 viewed superbowl commericals, 10 are Doritos and 6 Bud Light
youtube %>%
arrange(desc(view_count)) %>%
head(30) %>%
count(brand) %>%
arrange(desc(n)) %>%
top_n(2)
```
```{r}
library(showtext)
font_add("MALDINIBold", "/Users/kristenakey/Library/Fonts/MaldiniBold-OVZO6.ttf")
showtext_auto()
font_add("SoccerLeague-Regular", "/Users/kristenakey/Library/Fonts/SoccerLeague.ttf")
```
```{r}
df <- youtube %>%
arrange(desc(view_count)) %>%
filter(year>=2004) %>%
filter(brand %in% c("Doritos", "Bud Light")) %>%
group_by(brand, year) %>%
top_n(n = 1,view_count) %>%
mutate(views_tot = ifelse(brand == "Doritos",
log(view_count),
-1*log(view_count))) %>%
select(year, brand, views_tot, like_count)
field_label = c("0 4", "0 6", "0 8", "1 0", "1 2",
"1 4", "1 6", "1 8", "2 0"
)
x_cord <- seq(2004.03, 2020.03, 2)
y_cord <- rep(-18, 9)
labelsdf <- data.frame(field_label, x_cord, y_cord)
# to add space between bars at 0
# (needs to be a val greater than 0)
val_change <- 0
p <- ggplot()+
geom_vline(xintercept = c(seq(2004,2020)), color="white") +
geom_segment(data=df %>% filter(brand=="Doritos"),
aes(x=year, y=val_change, xend=year, yend=views_tot+val_change),
color="#AF2317", size=3) +
geom_segment(data=df %>% filter(brand=="Bud Light"),
aes(x=year, y=-val_change, xend=year,
yend=views_tot-val_change),
color="#204D8D", size=3) +
geom_text(data=labelsdf, aes(x=x_cord,y_cord,label=field_label, angle=0,
family="MALDINIBold"),size=5, color="white") +
scale_y_continuous(labels=c("-20" = "20", "-10" = "10",
"0" = "0", "10" = "10", "20" = "20"),
# dual y-axis
sec.axis = sec_axis(trans=~.*1,
name="Logged Total Views",
labels=c("-20" = "20", "-10" = "10",
"0" = "0", "10" = "10", "20" = "20"))
) +
ggtitle("<span style = 'color:#AF2317'>**Doritos**</span> vs
<span style = 'color:#204D8D'>**Bud Light**</span>") +
labs(caption = "Data: FiveThirtyEight | @kkakey") +
theme(text = element_text(family="SoccerLeague-Regular"),
legend.position = "none",
plot.title = element_markdown(size=28, hjust = .5,
margin = margin(t = -60, b = 60)),
plot.margin = unit(c(t=3,r=2.3,b=1,l=2.3), "cm"),
panel.background = element_rect(color="#009A17", fill="#009A17"),
plot.background = element_rect(color="#009A17", fill="#009A17"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x = element_blank(), axis.ticks = element_blank(),
plot.subtitle = element_text(hjust=.5, vjust=43),
plot.caption = element_text(color="white", hjust=1.1, size=6,
margin = margin(t = 23, b = -23)),
axis.text.y = element_text(color="white"),
axis.title = element_text(color="white"),
) +
geom_text(aes(x=2012, y=28, label="Most Viewed Superbowl Ads by these Brands Over Time",
lineheight = .8), family="SoccerLeague-Regular", fill = NA, label.color = NA) +
geom_text(aes(x=2012, y=25.2, label="Of the top 30 most viewed superbowl commericals in the dataset, one-thrid are Doritos and one-fifth are Bud Light.\nThis plot shows the logged view count of each company's top commericals from 2004 to 2020.",
lineheight = .8), size=4, fill = NA, label.color = NA) +
geom_curve(aes(x = 2012.5, y = 16, xend = 2012.1, yend = 15),
curvature = -.3,
arrow = arrow(length = unit(0.01, "npc"))) +
geom_text(aes(x=2012.55, y=18,
label="Most viewed\nsuperbowl ad\nwith over\n176 million\nwatches",
lineheight = .8), size=2.2,
fill = NA, label.color = NA) +
geom_text(aes(x=2019.55, y=-15,
label="Bud Light's\nmost watched\ncommercial,\n7.7 million\nviews",
lineheight = .8), size=2.2,
fill = NA, label.color = NA) +
geom_curve(aes(x = 2019.55, y = -13, xend = 2019.15, yend = -12),
curvature = .5, arrow = arrow(length = unit(0.01, "npc"))) +
coord_cartesian(clip = 'off', ylim = c(-20,20)) +
scale_x_continuous(limits = c(2003.6,2020.4), expand = c(0, 0)) +
ylab("Logged Total Views")
ggsave("plot2.pdf", width=12, dpi=800, device="pdf")
```