Last active
December 30, 2015 19:17
-
-
Save WillForan/a5eecf37ee532507b551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
library(tidyr) | |
##DATA | |
WM <- structure(list(ID = structure(1:32, .Label = c("10843_20151015", | |
"11228_20150309", "11339_20141104", "11340_20141031", "11341_20141118", | |
"11348_20141119", "11349_20141124", "11351_20141202", "11352_20141230", | |
"11354_20141205", "11355_20141230", "11356_20150105", "11357_20150122", | |
"11358_20150129", "11359_20150203", "11360_20150129", "11363_20150310", | |
"11365_20150407", "11367_20150430", "11368_20150505", "11369_20150519", | |
"11374_20150529", "11386_20150619", "11390_20150721", "11407_20150716", | |
"11418_20151201", "11423_20150916", "11424_20150908", "11432_20150922", | |
"11433_20150924", "11454_20151019", "11466_20151125"), class = "factor"), | |
Cohort = structure(c(2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, | |
1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, | |
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), .Label = c("Clinical", "Control" | |
), class = "factor"), condition = structure(c(1L, 1L, 1L, | |
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, | |
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "0[delay_ld1]", class = "factor"), | |
CB_ld1 = c(-16.281676, -5.017022, -5.227623, 3.343006, -8.728013, | |
-1.673829, -2.75081, 8.145376, 2.876325, -0.918119, 7.712771, | |
-7.031173, -4.108706, -0.983761, -1.270249, -5.455893, 10.909173, | |
-4.585588, 0.217045, -0.777112, -5.737579, -4.112495, 0.951513, | |
-7.242032, -1.584525, 3.626982, 0.24173, 2.941472, 2.201748, | |
-3.817421, 9.010105, -0.619158), R_DLPFC_ld1 = c(-14.062443, | |
12.302224, 9.5302, 7.125673, -4.699015, 8.689309, 6.595875, | |
22.019142, 1.856274, -5.466109, 16.465215, -19.421602, 4.765969, | |
-5.260434, 3.913552, -11.227274, 34.114333, -4.050198, 16.788266, | |
6.188547, 19.822619, 6.039495, 12.00768, 10.942528, 17.668428, | |
12.03592, 28.771312, -8.235222, 30.612336, -0.401151, 21.059559, | |
1.263492), CB_ld3 = c(-0.321061, 3.125329, 5.64455, 1.283899, | |
-2.637401, -0.953091, -1.279139, -1.536689, 1.100666, -3.279125, | |
-6.739991, 3.772425, -2.765257, 3.725869, -0.157239, -10.725254, | |
-8.323062, -0.134436, -4.7262, -2.810531, -4.83956, 2.507507, | |
-4.606195, 8.076474, -7.005166, -2.298958, -1.281827, -11.093254, | |
2.375286, -0.834906, -3.126058, -2.295052), R_DLPFC_ld3 = c(16.879131, | |
15.386749, 37.125275, 23.745324, 15.742828, 10.105206, 4.72799, | |
-11.066886, 5.702247, 3.33002, 18.208506, 31.60593, 6.52933, | |
65.439944, 12.56645, -8.036658, -13.942518, 9.507799, 5.284815, | |
9.549544, -1.01616, 15.026034, -18.944697, 42.337117, -26.115444, | |
-1.401052, 25.448017, -22.440274, 22.527186, 10.789422, -2.151482, | |
-10.630512)), .Names = c("ID", "Cohort", "condition", "CB_ld1", | |
"R_DLPFC_ld1", "CB_ld3", "R_DLPFC_ld3"), class = "data.frame", row.names = c(NA, | |
-32L)) | |
### Summarise Data | |
names(WM)[c(5,7)] <- c('low','high') | |
graph_data <- WM %>% | |
# gather BOLD value in columns 'low' and 'high' into one column called 'BOLD' | |
# with a new 'load' column indicating if the BOLD value came from 'high' or 'low' | |
gather(load,BOLD,low,high) %>% | |
# group by cohort and load | |
group_by(Cohort,load) %>% | |
# get mean and se | |
summarise(mu=mean(BOLD), | |
se=sd(BOLD)/sqrt(n()) ) %>% | |
# get se bounds for errorbar | |
mutate(ymin=mu-se,ymax=mu+se) | |
### Plot Data | |
p <- ggplot(data=graph_data) + | |
# load by mean, color and shape by group | |
aes(x=load, y=mu, | |
color=Cohort, | |
linetype=Cohort, | |
fill=Cohort, | |
shape=Cohort,group=Cohort, | |
ymax=ymax, ymin=ymin) + | |
# line first so shapes are on top | |
geom_line()+ | |
geom_errorbar(width=.25)+ | |
geom_point(size=15)+ | |
# style points: | |
# filled square and diamond of two gray colors | |
scale_shape_manual(values = c(22, 23))+ | |
scale_fill_manual(values=c("#404040","#ACACAC")) + | |
scale_color_manual(values=c("#404040","#ACACAC")) + | |
# labels | |
xlab("Load") + | |
ylab("% BOLD Chage") + | |
# graph display settings | |
coord_cartesian(ylim=c(-20,20))+ | |
theme_bw(base_size=20)+ | |
theme(legend.position="none")+ | |
theme(panel.border = element_blank(), | |
panel.grid.major = element_blank(), | |
panel.grid.minor = element_blank(), | |
axis.line = element_line(colour = "black")) | |
print(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment