-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrapher.R
More file actions
55 lines (50 loc) · 2.34 KB
/
Grapher.R
File metadata and controls
55 lines (50 loc) · 2.34 KB
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
Grapher <- function(scores) {
# Adjust player data ------------------------------------------------------
player_data =
scores %>%
# remove rat scores
filter(str_detect(player, pattern = "Rat", negate = TRUE)) %>%
# artificially assign an intensity value
rename(`40` = quiet, `90` = loud) %>%
# convert to long format
tidyr::gather(key = "intensity", value = "reaction", num_range("", 10:90)) %>%
mutate(intensity = as.numeric(intensity))
# Make Player graph --------------------------------------------------------
Player_graph =
player_data %>%
# may need to convert from low, medium, high to number using mutate
ggplot(aes(x = intensity, y = reaction, color = as.factor(player), group = as.factor(player))) +
stat_summary(fun = mean, geom = "line", linewidth = 2) +
stat_summary(fun = mean, geom = "point", size = 5)
# Add rat & human average data ---------------------------------------------
Final_graph =
Player_graph +
# Rat data
geom_smooth(data = rat_data,
se = FALSE, na.rm = TRUE, linewidth = 2, linetype = "dotdash",
method = "lm", formula = y ~ x
) +
geom_smooth(data = Human_data,
se = FALSE, na.rm = TRUE, linewidth = 2, linetype = "dotdash",
method = "lm", formula = y ~ x
) +
scale_color_manual(values = c(
"Purple" = "mediumorchid", "White" = "grey99", "Green" = "seagreen3", "Blue" = "royalblue", "Rat" = "gold", "Human" = "firebrick3"
)) +
labs(x = "Loudness\n(Intensity, dB)",
y = "Speed\n(Average reaction time, ms)",
color = "Player") +
scale_x_continuous(breaks = seq(-50, 90, by = 10)) +
labs(title = "*Are you quicker than a lab rat?* <span style='color:#CD2626;'>Human</span> vs <span style='color:#FFD700;'>Rat</span> hearing and reaction time") +
theme(plot.title = element_text(hjust = 0.5)) +
annotate(geom = "text", x = 38, y = c(12, max(player_data$reaction, rat_data$reaction)),
label = c("Fast", "Slow" ), size = 8) +
annotate(geom = "text", x = c(42,88), y = -12,
label = c("Quiet", "Loud" ), size = 8) +
theme_ft_rc() +
theme(
plot.title = element_markdown(size = 54, hjust = 0.5)
)
print(Final_graph)
return(Final_graph)
}