-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path99991-ggplot2_3way_SS.R
83 lines (73 loc) · 3.61 KB
/
99991-ggplot2_3way_SS.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
## this script is meant to be sourced from other scripts ##
###########################################
####### Run code but do not modify ########
###########################################
# regression
step3 <- lm(y ~ z * x * w, data=dat)
# create figure
data_plot <- probe_interaction(step3,
pred = z,
modx = x,
mod2 = w,
modx.values = "plus-minus",
mod2.values = "plus-minus")
### tells R to provide a plot in APA style, figure is MS ready
apatheme = theme_bw() +
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.border=element_blank(),
axis.line=element_line(),
text=element_text(family='Times'))
# create Panel A
panel_a <- data_plot$interactplot$data %>%
filter(mod2_group == "Mean of w - 1 SD") %>%
ggplot(aes(x = z, y = y, group = modx_group)) +
geom_line(aes(color = modx_group,
linetype = modx_group),
linewidth = 1.25) +
scale_y_continuous(limits = c(y_axis_low, y_axis_high),
breaks = seq(y_axis_low, y_axis_high, y_increment)) +
labs(subtitle = panel_a_label) +
ylab(y_label) +
xlab(z_label) +
scale_x_discrete(limits = z_range,
labels = z_values) +
scale_linetype_manual(name = modx_label,
labels = modx_values,
values = line_types,
guide = guide_legend(reverse = TRUE)) +
scale_colour_manual(name = modx_label,
labels = modx_values,
values = line_colors,
guide = guide_legend(reverse = TRUE)) +
apatheme +
theme(legend.position = legend_loc) +
scale_fill_grey()
# ggsave('./figures/figure_1_panel_a.png', width=8, height=6, unit='in', dpi=300)
# create Panel B
panel_b <- data_plot$interactplot$data %>%
filter(mod2_group == "Mean of w + 1 SD") %>%
ggplot(aes(x = z, y = y, group = modx_group)) +
geom_line(aes(color = modx_group,
linetype = modx_group),
linewidth = 1.25) +
scale_y_continuous(limits = c(y_axis_low, y_axis_high),
breaks = seq(y_axis_low, y_axis_high, y_increment)) +
labs(subtitle = panel_b_label) +
ylab(y_label) +
xlab(z_label) +
scale_x_discrete(limits = z_range,
labels = z_values) +
scale_linetype_manual(name = modx_label,
labels = modx_values,
values = line_types,
guide = guide_legend(reverse = TRUE)) +
scale_colour_manual(name = modx_label,
labels = modx_values,
values = line_colors,
guide = guide_legend(reverse = TRUE)) +
apatheme +
theme(legend.position = legend_loc) +
scale_fill_grey()
# combine plots into a single image
panel_a_b <- panel_a / panel_b