-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
w42_stranger_things_dialogue.R
126 lines (100 loc) · 4.49 KB
/
w42_stranger_things_dialogue.R
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
120
121
122
123
124
library(tidyverse)
library(showtext)
library(sysfonts)
library(extrafont)
library(ggridges)
library(cowplot)
# set the fonts
showtext::showtext_auto()
showtext::showtext_opts(dpi=320)
font.add(family = "Benguiat",regular="Benguiat Normal.ttf")
episodes_raw <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-10-18/stranger_things_all_dialogue.csv')
df <-
episodes_raw %>%
filter(!is.na(dialogue)) %>%
mutate(season = paste("Season", season)) %>%
select(season,episode,start_time,end_time,dialogue) %>%
mutate(time = end_time-start_time,
time = as.numeric(time),
trims = trimws(dialogue),
space = sapply(strsplit(trims, " "), length)) %>% #pull(time)%>%summary()
filter(time > 1) %>%
mutate(velocity = space/(time/60)) %>%
mutate(time_s=time,
time = time/60)
p <- df %>%
group_by(season,episode)%>%
mutate(velocity=mean(velocity))%>%
ungroup()%>%
ggplot(aes(x = velocity,y = fct_reorder(factor(episode),desc(episode)),
fill = 0.5 - abs(0.5 - stat(ecdf)))) +
ggridges::stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE, alpha=0.5) +
scale_fill_viridis_c(name = "Speed wpm", option = "A",labels = scales::percent) +
scale_x_continuous(expand = c(0,0)) +
labs(title="All seasons episodes",
caption="DataSource: #TidyTuesday 2022 week 42 by Stranger things dialogue | DataViz: Federica Gazzelloni (@fgazzelloni)",
x="Dialogue speech speed (wpm)",y="Episode")+
ggridges::theme_ridges()+
theme(text=element_text(color="grey90",family="Benguiat"),
axis.text.x = element_text(color="grey90",size=9),
axis.text.y = element_text(color="grey90",size=9),
plot.margin = margin(10,10,10,10,unit = "pt"),
plot.title = element_text(size=12,hjust = 0.03),
plot.title.position = "panel",
plot.subtitle = element_text(color="grey90"),
plot.caption = element_text(size=10),
plot.caption.position = "plot",
plot.background = element_rect(color="grey10",fill="grey10"),
panel.background = element_rect(color="grey10",fill="grey10"),
strip.background = element_blank(),
legend.text = element_text(size=9),
legend.title = element_text(size=8))
ggsave("p.png",dpi=400,width = 8,height = 4)
p1 <- ggplot(df,
aes(x = time, y = velocity,group=space)) +
geom_jitter(aes(color=factor(season)),
size=0.2,
alpha=0.3)+
geom_line(aes(color=factor(season)),
size=0.2,
alpha=0.5) +
scale_y_continuous(expand = c(0,0)) +
scale_color_viridis_d(option = "A")+
labs(title = "Talking fast slows down as time increases\n",
y = "Speed (wpm)", x = "Time in minutes")+
ggridges::theme_ridges()+
theme(text=element_text(color="grey90",size=14,family="Benguiat"),
axis.text.x = element_text(color="grey90"),
axis.text.y = element_text(color="grey90"),
axis.line = element_line(color="grey90",
arrow = arrow(type='closed',
length = unit(10,'pt'))),
panel.grid.major = element_line(color="grey60",size=0.1,linetype = "dashed"),
plot.margin = margin(10,10,10,10,unit = "pt"),
plot.subtitle = element_text(color="grey90"),
plot.caption = element_text(size=11),
plot.background = element_rect(color="grey10",fill="grey10"),
panel.background = element_rect(color="grey10",fill="grey10"),
strip.background = element_blank(),
legend.position = "none")
ggsave("p1.png",dpi=300,width = 9,height = 4)
cowplot::ggdraw()+
draw_image("p.png",scale=0.93,x=-0.02,y=-0.22)+
draw_image("p1.png",scale=0.7, y=0.22,x=-0.13)+
draw_image("logo.png",scale = 0.2,y=0,x=0.4)+
draw_label("Stranger things...on dialogue's speed",
fontfamily = "Benguiat",
x=0.4,y=0.95,
size=25,
color="grey90")+
draw_label("wpm = word/per minutes\n\nWord Speed:\nnumber of words\ndivided by time difference\nfrom end to start\n\nAvg 2.5 words per second\n\n\nSlow: less than 110 wpm\nConversational: 120 - 150 wpm\nFast: more than 160 wpm",
x=0.96,y=0.74,color="grey90",
hjust = 1,
size=9,
lineheight = 1.5,
fontfamily = "Benguiat")+
theme(plot.background = element_rect(fill="grey10", color = "grey10"))
ggsave("w42_stranger_things_dialogue.png",
dpi=200,
width = 14,
height = 12)