-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure5.R
138 lines (120 loc) · 7.02 KB
/
Figure5.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
## =======================================
# Cog-scores (baseline) ~ IndexB_roa Delta
## =======================================
library(ggpubr)
library(MASS)
library(data.table)
library(lemon)
library(gtable)
pheno_compare$`Trail Making B-A Subtraction` = pheno_compare$Trail_Making_B - pheno_compare$Trail_Making_A
scatter_dataset = pheno_compare[, c("id", "IndexB.RoA", "tHcy", "atrophyRate_year", "treatment", "visit",
"Category_fluency",
"HVLT_TR", "HVLT_DR",
"SRM",
"Graded_naming",
"Trail_Making_A", "Trail_Making_B",
"Trail Making B-A Subtraction",
"SDMT",
"Map_Search",
"MMSE")]
scatterF = scatter_dataset[scatter_dataset$visit == "F",]
scatterR = scatter_dataset[scatter_dataset$visit == "R" & scatter_dataset$id %in% scatterF$id,]
scatterF = scatterF[scatterF$id %in% scatterR$id,]
scatterR = scatterR[order(scatterR$id),]
scatterF = scatterF[order(scatterF$id),]
scatterR[,c("IndexB_roa_delta")] = scatterF[,c("IndexB.RoA")] - scatterR[,c("IndexB.RoA")]
scatterF[,c("IndexB_roa_delta")] = scatterF[,c("IndexB.RoA")] - scatterR[,c("IndexB.RoA")]
scatter_final = rbind(scatterR[,-2], scatterF[,-2])
rm(scatter_dataset, scatterF, scatterR)
scatter_final = melt(scatter_final, id.vars = c("id", "IndexB_roa_delta", "tHcy", "atrophyRate_year", "treatment", "visit"), variable.name = "cog_test")
scatter_final$treatment = ifelse(scatter_final$treatment == "active", "B-vitamin complex", "Placebo")
scatter_final$treatment = factor(scatter_final$treatment, levels = c("Placebo", "B-vitamin complex"))
# Main manuscript figure
main.labs = c("Category Fluency", "HVLT-R DR", "MMSE")
names(main.labs) = c("Category_fluency", "HVLT_DR", "MMSE")
plt1 = ggplot(scatter_final[scatter_final$visit == "R" & scatter_final$cog_test %in% c("MMSE", "HVLT_DR", "Category_fluency"),],
aes(x=value,
y=IndexB_roa_delta,
group=treatment)) +
geom_point(aes(shape = treatment), alpha = 0.1) +
coord_cartesian(ylim = c(NA, 0.1)) +
geom_smooth(method = "lm", aes(group = treatment, color = treatment), fill = "grey") +
# geom_smooth(method = "lm", aes(group = treatment, color = treatment), se = FALSE) +
theme_bw() +
theme(legend.position = "bottom", text = element_text(size = 14),
# axis.text.x = element_text(angle = 90, hjust=1),
axis.text.y = element_text(size = 12),
plot.title = element_text(size=15),
axis.title = element_text(size = 12),
panel.spacing = unit(1, "lines")) +
labs(title = expression("Index ROA"*Delta~"~ Cognitive Scores (baseline)"),
y = expression("Index 2-Year ROA"*Delta),
x = "Cognitive Score (baseline)") +
facet_wrap(vars(cog_test), scales = "free_x", labeller = labeller(cog_test = main.labs)) +
stat_cor(method = "pearson", aes(color = treatment), show.legend = F, label.x.npc = "left", label.y.npc = 0.59) +
ggsci::scale_color_jco() + ggsci::scale_fill_jco()
formula = y ~ x
plt1.1 = ggplot(scatter_final[scatter_final$visit == "R" & scatter_final$cog_test %in% c("HVLT_DR"),],
aes(x=value,
y=IndexB_roa_delta,
group=treatment)) +
geom_point(aes(shape = treatment), alpha = 0.3) +
coord_cartesian(ylim = c(NA, 0.1)) +
geom_smooth(method = "lm", aes(group = treatment, color = treatment), fill = "lightgrey") +
theme_bw() + labs(title = "A") +
theme(legend.position = "bottom", text = element_text(size = 14),
axis.text.y = element_text(size = 12),
plot.title = element_text(size=15),
axis.title = element_text(size = 12),
panel.spacing = unit(1, "lines")) +
labs(y = expression("Index 2-Year ROA"*Delta),
x = "Cognitive Score (baseline)") +
facet_wrap(vars(cog_test), scales = "free_x", labeller = labeller(cog_test = main.labs)) +
stat_regline_equation(aes(color = treatment),show.legend = F, label.x.npc = "left", label.y.npc = 0.59, lineheight = 1) +
stat_cor(method = "pearson", cor.coef.name = "r", aes(color = treatment), show.legend = F, label.x.npc = "left", label.y.npc = 0.5) +
ggsci::scale_color_jco() + ggsci::scale_fill_jco()
plt1.2 = ggplot(scatter_final[scatter_final$visit == "R" & scatter_final$cog_test %in% c("MMSE"),],
aes(x=value,
y=IndexB_roa_delta,
group=treatment)) +
geom_point(aes(shape = treatment), alpha = 0.3) +
coord_cartesian(ylim = c(NA, 0.1)) +
geom_smooth(method = "lm", aes(group = treatment, color = treatment), fill = "lightgrey") +
theme_bw() + labs(title = "B") +
theme(legend.position = "bottom", text = element_text(size = 14),
axis.text.y = element_text(size = 12),
plot.title = element_text(size=15),
axis.title = element_text(size = 12),
panel.spacing = unit(1, "lines")) +
labs(y = expression("Index 2-Year ROA"*Delta),
x = "Cognitive Score (baseline)") +
facet_wrap(vars(cog_test), scales = "free_x", labeller = labeller(cog_test = main.labs)) +
stat_regline_equation(aes(color = treatment),show.legend = F, label.x.npc = "left", label.y.npc = 0.59, lineheight = 1) +
stat_cor(method = "pearson", cor.coef.name = "r", aes(color = treatment), show.legend = F, label.x.npc = "left", label.y.npc = 0.5) +
ggsci::scale_color_jco() + ggsci::scale_fill_jco()
plt1.3 = ggplot(scatter_final[scatter_final$visit == "R" & scatter_final$cog_test %in% c("Category_fluency"),],
aes(x=value,
y=IndexB_roa_delta,
group=treatment)) +
geom_point(aes(shape = treatment), alpha = 0.3) +
coord_cartesian(ylim = c(NA, 0.1)) +
geom_smooth(method = "lm", aes(group = treatment, color = treatment), fill = "lightgrey") +
theme_bw() + labs(title = "C") +
theme(legend.position = "bottom", text = element_text(size = 14),
axis.text.y = element_text(size = 12),
plot.title = element_text(size=15),
axis.title = element_text(size = 12),
panel.spacing = unit(1, "lines")) +
labs(y = expression("Index 2-Year ROA"*Delta),
x = "Cognitive Score (baseline)") +
facet_wrap(vars(cog_test), scales = "free_x", labeller = labeller(cog_test = main.labs)) +
stat_regline_equation(aes(color = treatment),show.legend = F, label.x.npc = "left", label.y.npc = 0.59, lineheight = 1) +
stat_cor(method = "pearson", cor.coef.name = "r", aes(color = treatment), show.legend = F, label.x.npc = "left", label.y.npc = 0.5) +
ggsci::scale_color_jco() + ggsci::scale_fill_jco()
# Patchwork plot
(plt1.1 + plt1.2 + plt1.3) +
plot_layout(axis_titles = "collect", guides = "collect") & theme(legend.position = "bottom")
ggsave(filename = "Figure_5.png", path = "~/Google Drive/My Drive/Vitacog paper workup data/",
width = 9, height = 7.5, units = "in", dpi = 600)
rm(scatter_final, main.labs, xlab1, formula)
rm(list = grep("plt", ls(), value = T))