Calculate endpoint variability, as standard deviation of the horizontal component (x-coordinate) of saccades
varMeanLeg <- preproc %>%
group_by(subject,stimulation,leg,direction,type) %>%
summarise(std.deviation.x = sd(deviation.end.x)) %>% # standard deviation
ungroup() %>%
mutate(leg = as.character(leg), # edit leg factor to match other data frames
leg = replace(leg, leg == "pre", "baseline"),
leg = factor(leg, levels = c("baseline", "tDCS", "post.1", "post.2"))
)
Make a separate data frame where the mean variability is subtracted from subsequent blocks
varMeanBaseline <- varMeanLeg %>%
group_by(subject,stimulation,direction,type) %>% # for each condition, subtract baseline scores and make new columns
summarise(baseline = std.deviation.x[leg == "baseline"] - std.deviation.x[leg == "baseline"],
tDCS = std.deviation.x[leg == "tDCS"] - std.deviation.x[leg == "baseline"],
post.1 = std.deviation.x[leg == "post.1"] - std.deviation.x[leg == "baseline"],
post.2 = std.deviation.x[leg == "post.2"] - std.deviation.x[leg == "baseline"]) %>%
gather(leg, std.deviation.x.baseline, baseline, tDCS, post.1, post.2) %>% # gather new columns to use as factor
mutate(leg = factor(leg, levels = c("baseline", "tDCS", "post.1", "post.2"))) # reorder factor levels
Figure 7
baselineLabelVar <- varMeanLeg %>%
group_by(stimulation,direction,type,leg) %>%
filter(leg == "baseline") %>%
summarise(std.deviation.x.baseline = round(mean(std.deviation.x), digits = 2))
Plot mean lateral saccade variability per participant
plot_sub_var_lateral <- ggplot(filter(varMeanLeg, type == "lateral"), aes(leg, std.deviation.x)) +
facet_grid(stimulation ~ direction) +
geom_line(aes(group = subject, color = subject), alpha = 0.5) +
stat_summary(fun.y = mean, aes(group = interaction(stimulation, direction), linetype = direction), geom = "line") +
stat_summary(fun.y = mean, geom = "point", aes(shape = stimulation)) +
guides(colour = FALSE) +
scale_x_discrete("time", labels = c("baseline", "tDCS", "post-1", "post-2")) +
scale_y_continuous(expression("standard deviation " ( degree)), breaks = seq(0.5,2,0.5), limits = c(0,2)) +
theme(axis.text.x = element_text(angle = 22, vjust = .5), axis.title.x = element_blank(), legend.position = "none") +
ggtitle("Lateral saccades")
Plot mean center saccade variability per participant
plot_sub_var_center <- ggplot(filter(varMeanLeg, type == "center"), aes(leg, std.deviation.x)) +
facet_grid(stimulation ~ direction) +
geom_line(aes(group = subject, color = subject), alpha = 0.5) +
stat_summary(fun.y = mean, aes(group = interaction(stimulation, direction), linetype = direction), geom = "line") +
stat_summary(fun.y = mean, geom = "point", aes(shape = stimulation)) +
guides(colour = FALSE) +
scale_x_discrete("time", labels = c("baseline", "tDCS", "post-1", "post-2")) +
scale_y_continuous(expression("standard deviation " ( degree)), breaks = seq(0.5,2,0.5), limits = c(0,2)) +
theme(axis.text.x = element_text(angle = 22, vjust = .5), axis.title.x = element_blank(), legend.position = "none") +
ggtitle("Center saccades")
Plot group mean lateral saccade variability as change from baseline
plot_group_var_lateral <- ggplot(filter(varMeanBaseline, type == "lateral"), aes(leg, std.deviation.x.baseline)) +
geom_hline(yintercept = 0, linetype = "dashed", size = base_line_size) +
stat_summary(fun.y = mean, aes(group = interaction(stimulation, direction), color = stimulation, linetype = direction), geom = "line", position = position_dodge(width = 0.5), size = .75) +
stat_summary(fun.data = mean_cl_normal, aes(group = interaction(stimulation, direction), color = stimulation, linetype = direction), geom = "linerange", position = position_dodge(width = 0.5), show.legend = FALSE) +
stat_summary(fun.y = mean, aes(group = interaction(stimulation, direction), color = stimulation, shape = stimulation), geom = "point", position = position_dodge(width = 0.5), size = 2) +
geom_text(data = subset(baselineLabelVar, type=="lateral"), aes(y = c(.05,.025,.1,.075), label=(std.deviation.x.baseline), color = stimulation), position = position_dodge(width = 0.5), size = mm_to_pt) +
scale_x_discrete("time", labels = c("baseline", "tDCS", "post-1", "post-2")) +
scale_colour_manual(values = c("#F25F5C", "#4B93B1")) +
scale_y_continuous(expression("SD change from baseline " ( degree)), breaks = seq(-.2,.2,.1)) +
coord_cartesian(ylim = c(-.2,.2)) +
theme(axis.text.x = element_text(angle = 22, vjust = .5), axis.title.x = element_blank())
Plot group mean center saccade variability as change from baseline
plot_group_var_center <- ggplot(filter(varMeanBaseline, type == "center"), aes(leg, std.deviation.x.baseline)) +
geom_hline(yintercept = 0, linetype = "dashed", size = base_line_size) +
stat_summary(fun.y = mean, aes(group = interaction(stimulation, direction), color = stimulation, linetype = direction), geom = "line", position = position_dodge(width = 0.5), size = .75) +
stat_summary(fun.data = mean_cl_normal, aes(group = interaction(stimulation, direction), color = stimulation, linetype = direction), geom = "linerange", position = position_dodge(width = 0.5), show.legend = FALSE) +
stat_summary(fun.y = mean, aes(group = interaction(stimulation, direction), color = stimulation, shape = stimulation), geom = "point", position = position_dodge(width = 0.5), size = 2) +
geom_text(data = subset(baselineLabelVar, type=="center"), aes(y = c(.05,.025,.1,.075), label=(std.deviation.x.baseline), color = stimulation), position = position_dodge(width = 0.5), size = mm_to_pt) +
scale_colour_manual(values = c("#F25F5C", "#4B93B1")) +
scale_x_discrete("time", labels = c("baseline", "tDCS", "post-1", "post-2")) +
scale_y_continuous(expression("SD change from baseline " ( degree)), breaks = seq(-.2,.2,.1)) +
coord_cartesian(ylim = c(-.2,.2)) +
theme(axis.text.x = element_text(angle = 22, vjust = .5), axis.title.x = element_blank())
Combine all the plots:
legend_fig7 <- get_legend(plot_group_acc_lateral)
figure_7 <- plot_grid(
plot_sub_var_lateral, plot_sub_var_center,
plot_group_var_lateral + theme(legend.position = "none"),
plot_group_var_center + theme(legend.position = "none"), rel_heights = c(1,.75))
figure_7 <- plot_grid(figure_7,legend_fig7,rel_widths = c(1,1/10))
figure_7
Save the plot:
ggsave("fig/figure_7.pdf", plot = figure_7, width = 180, height = 112.5, units = "mm")
ggsave("fig/figure_7.png", plot = figure_7, width = 180, height = 112.5, units = "mm")