forked from tonymatthews/validate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
an_kaplanmeier.R
122 lines (103 loc) · 4.76 KB
/
an_kaplanmeier.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
for(i in outcomes) {
if (i == "composite") {
dat_surv <- dat_composite
}
if (i == "death") {
dat_surv <- dat_death
}
if (i == "mi") {
dat_surv <- dat_mi
}
if (i == "bleed") {
dat_surv <- dat_bleed
}
#create survival times
dat_surv <- dat_surv %>%
mutate(survtime = ifelse(event_180==0, 180,
date_event-interdat)) %>%
arrange(survtime)
# Create unweighted survival model
assign(paste0("model_", i), survfit(Surv(survtime, event_180) ~ exp, data=dat_surv))
} # end for (i in outcomes)
splots <- list()
splots[[1]] <- ggpar(ggsurvplot(model_composite,
ylim=c(0.85,1),
xlim=c(0,180),
censor = FALSE,
break.time.by = 30,
title = "Composite",
font.main = c(22),
font.x = c(22),
font.y = c(22),
legend = c(0.3,0.3),
legend.title = "",
legend.labs = c("Heparin", "Bivalirudin"),
palette = c("#00BFC4", "#F8766D"),
linetype = c("dotted", "solid"),
xlab = "Days",
risk.table = FALSE,
tables.theme = theme_cleantable()),
font.legend = list(size=18)
)
splots[[3]] <- ggpar(ggsurvplot(model_death,
ylim=c(0.85,1),
xlim=c(0,180),
censor = FALSE,
break.time.by = 30,
title = "Death",
font.main = c(22),
font.x = c(22),
font.y = c(22),
legend = c(0.3,0.3),
legend.title = "",
legend.labs = c("Heparin", "Bivalirudin"),
palette = c("#00BFC4", "#F8766D"),
linetype = c("dotted", "solid"),
xlab = "Days",
risk.table = FALSE,
tables.theme = theme_cleantable()),
font.legend = list(size=18)
)
splots[[2]] <- ggpar(ggsurvplot(model_mi,
ylim=c(0.85,1),
xlim=c(0,180),
censor = FALSE,
break.time.by = 30,
title = "Myocardial infarction",
font.main = c(22),
font.x = c(22),
font.y = c(22),
legend = c(0.3,0.3),
legend.title = "",
legend.labs = c("Heparin", "Bivalirudin"),
palette = c("#00BFC4", "#F8766D"),
linetype = c("dotted", "solid"),
xlab = "Days",
risk.table = FALSE,
tables.theme = theme_cleantable()),
font.legend = list(size=18)
)
splots[[4]] <- ggpar(ggsurvplot(model_bleed,
ylim=c(0.85,1),
xlim=c(0,180),
censor = FALSE,
break.time.by = 30,
title = "Bleeding",
font.main = c(22),
font.x = c(22),
font.y = c(22),
legend = c(0.3,0.3),
legend.title = "",
legend.labs = c("Heparin", "Bivalirudin"),
palette = c("#00BFC4", "#F8766D"),
linetype = c("dotted", "solid"),
xlab = "Days",
risk.table = FALSE,
tables.theme = theme_cleantable()),
font.legend = list(size=18)
)
#Put all of above plots in 2x2 panel
all_plots <- arrange_ggsurvplots(splots, print = TRUE, ncol = 2, nrow = 2)
#save to tiff
ggsave(paste0("logfiles/kmplots_180_", period, ".png"), all_plots, scale=2)
rm(all_plots, splots, model_composite, model_death, model_mi, model_bleed)