-
Notifications
You must be signed in to change notification settings - Fork 2
/
46b.R_CumIncSce3corig.R
121 lines (108 loc) · 5.53 KB
/
46b.R_CumIncSce3corig.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
############### Cumulative Incidence Plot: Scenario 3(Full method) case-study censoring #########################
setwd("path")
#install.packages("gghighlight")
library(ggplot2)
library(gghighlight)
## use ggnewscale to add several color scale in one plot
library(ggnewscale)
dataADL <- read.csv('CumIncSce3corig_adl.csv')
#dataADL0<-subset(dataADL, sim==0)
dataADLmean<-subset(dataADL, sim==501)
dataIADL <- read.csv('CumIncSce3corig_iadl.csv')
#dataIADL0<-subset(dataIADL, sim==0)
dataIADLmean<-subset(dataIADL, sim==501)
dataWalk <- read.csv('CumIncSce3corig_walk.csv')
#dataWalk0<-subset(dataWalk, sim==0)
dataWalkmean<-subset(dataWalk, sim==501)
dataDeath <- read.csv('CumIncSce3corig_death.csv')
#dataDeath0<-subset(dataDeath, sim==0)
dataDeathmean<-subset(dataDeath, sim==501)
dataAll <- read.csv('CumIncSce3corig_all.csv')
#dataAll0<-subset(dataAll, sim==0)
dataAllmean<-subset(dataAll, sim==501)
str(dataAll)
#str(dataAll0)
str(dataAllmean)
#Change the order of the outcomes
dataAll$outcome <- factor(dataAll$outcome, levels = c("adl", "iadl", "walk", "death"))
#dataAll0$outcome <- factor(dataAll0$outcome, levels = c("adl", "iadl", "walk", "death"))
dataAllmean$outcome <- factor(dataAllmean$outcome, levels = c("adl", "iadl", "walk", "death"))
# Modify labels for outcomes
dataAll$outcome <- factor(dataAll$outcome, levels = c("adl", "iadl", "walk","death"), labels = c("ADL", "IADL", "WALK", "DEATH"))
#dataAll0$outcome <- factor(dataAll0$outcome, levels = c("adl", "iadl", "walk","death"), labels = c("ADL", "IADL", "WALK", "DEATH"))
dataAllmean$outcome <- factor(dataAllmean$outcome, levels = c("adl", "iadl", "walk","death"), labels = c("ADL", "IADL", "WALK", "DEATH"))
########################### color version ##################################
png("CumIncSce3corig.png",width = 1800, height = 1500, res = 600)
ggplot() +
# draw the original cif series with grey
geom_line(aes(time, cif, group = sim, color=outcome), data = dataAll,alpha=0.7,size=0.01) +
##added color for simulation line (picked lighter color than the actual line)
scale_color_manual(guide = FALSE,values=c('#7FB3D5','#F5B7B1','#A9DFBF','#EDBB99'))+
# colorise only the filtered data
## added color for the actual line,
## new_scale_color() is used to use different color scale
#new_scale_color() +
#geom_line(aes(time, cif,color = outcome), data = dataAll0,size=0.2, lty=5) +
#scale_color_manual(guide = FALSE,values=c('blue','#ff0000','darkgreen','brown'))+
# do the same for the mean Cumulative Incidence function
new_scale_color() +
geom_line(aes(time, cif,color = outcome), data = dataAllmean,size=0.2) +
scale_color_manual(guide = FALSE,values=c('blue','#ff0000','darkgreen','brown'))+
#One panel / outcome
facet_wrap(~ outcome) +
#White background with grid lines
theme_bw() +
theme(strip.background =element_rect(color="black",fill="white")) +
theme(strip.text = element_text(face="bold")) +
##removed box around the facet title;decrese the margin between panels and text;
theme(strip.background = element_blank())+
theme(panel.spacing = unit(0.2, "lines"))+
theme(text = element_text(size=8))+
theme(strip.text.x = element_text( margin = margin( b = 1, t = 0) ) )+
#Change the x axis name
scale_x_continuous(name ="Time to event", breaks=seq(0,14,2)) +
labs(y="Cumulative Incidence") +
# Remove grid lines
# theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),)
theme(axis.title.x = element_text(face="bold")) +
theme(axis.title.y = element_text(face="bold")) +
theme(panel.grid.minor = element_line(size = 0.2),
panel.grid.major = element_line(size = 0.2))
dev.off()
pdf('CumIncSce3corig.pdf')
ggplot() +
# draw the original cif series with grey
geom_line(aes(time, cif, group = sim, color=outcome), data = dataAll,alpha=0.7,size=0.01) +
##added color for simulation line (picked lighter color than the actual line)
scale_color_manual(guide = FALSE,values=c('#7FB3D5','#F5B7B1','#A9DFBF','#EDBB99'))+
# colorise only the filtered data
## added color for the actual line,
## new_scale_color() is used to use different color scale
#new_scale_color() +
#geom_line(aes(time, cif,color = outcome), data = dataAll0,size=0.2, lty=5) +
#scale_color_manual(guide = FALSE,values=c('blue','#ff0000','darkgreen','brown'))+
# do the same for the mean Cumulative Incidence function
new_scale_color() +
geom_line(aes(time, cif,color = outcome), data = dataAllmean,size=0.2) +
scale_color_manual(guide = FALSE,values=c('blue','#ff0000','darkgreen','brown'))+
#One panel / outcome
facet_wrap(~ outcome) +
#White background with grid lines
theme_bw() +
theme(strip.background =element_rect(color="black",fill="white")) +
theme(strip.text = element_text(face="bold")) +
##removed box around the facet title;decrese the margin between panels and text;
theme(strip.background = element_blank())+
theme(panel.spacing = unit(0.2, "lines"))+
theme(text = element_text(size=12))+
theme(strip.text.x = element_text( margin = margin( b = 1, t = 0) ) )+
#Change the x axis name
scale_x_continuous(name ="Time to event", breaks=seq(0,14,2)) +
labs(y="Cumulative Incidence") +
# Remove grid lines
# theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),)
theme(axis.title.x = element_text(face="bold")) +
theme(axis.title.y = element_text(face="bold")) +
theme(panel.grid.minor = element_line(size = 0.2),
panel.grid.major = element_line(size = 0.2))
dev.off()