-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeline.R
193 lines (154 loc) · 8.19 KB
/
Timeline.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# dat1 <- Demo_RedCap_V4ish[, c("avatar_id", "Date_of_Birth")]
# ggplot(dat1, aes(Date_of_Birth, avatar_id)) +
# geom_point(size = 1) +
# labs(x="Birth", y=NULL, title="Birth timeline")
dat2 <- mm_history[, c("avatar_id", "date_of_diagnosis")]
# ggplot(dat2, aes(date_of_diagnosis, avatar_id)) +
# geom_point(size = 1, colour = "red") +
# labs(x="diagnosis", y=NULL, title="diagnosis timeline")
dat3 <- sct
dat3 <- dat3 %>% pivot_longer(c("date_of_first_bmt", "date_of_second_bmt", "date_of_third_bmt"),
names_to = "type", values_to = "bmt_date")
# ggplot(dat3, aes(bmt_date, avatar_id)) +
# geom_point(size = 1, colour = "green") +
# labs(x="BMT", y=NULL, title="BMT timeline")
dat4 <- radiation[, c("avatar_id", "rad_start_date")]
# dat4 <- dat4 %>% pivot_longer(c("rad_start_date", "rad_stop_date"),
# names_to = "type", values_to = "rad_date") %>%
# arrange(rad_date)
# ggplot(dat4, aes(rad_start_date, avatar_id)) +
# geom_point(size = 1, colour = "blue") +
# labs(x="Radiation", y=NULL, title="Radiation timeline")
dat5 <- treatment[, c("avatar_id", "drug_start_date")]
# dat5 <- dat5 %>% pivot_longer(c("drug_start_date", "drug_stop_date"),
# names_to = "type", values_to = "drug_date") %>%
# select(c("avatar_id", "type", "drug_date")) %>%
# arrange(drug_date)
# ggplot(dat5, aes(drug_start_date, avatar_id)) +
# geom_point(size = 1, colour = "orange") +
# labs(x="Treatment", y=NULL, title="Treatment timeline")
dat6 <- Vitals[, c("avatar_id", "date_death")]
dat7 <- Vitals[, c("avatar_id", "date_last_follow_up")]
all <- bind_rows(dat2, dat3,dat4,dat5,dat6,dat7) #%>%
# pivot_longer(c("rad_date", "drug_date"),
# names_to = "Type", values_to = "Dates")
ggpp <- ggplot()
ggpp +
geom_point(data=dat6, aes(date_death, avatar_id), colour = "black", alpha=1) +
geom_point(data=dat7, aes(date_last_follow_up, avatar_id), colour = "grey", alpha=1) +
geom_point(data=dat5, aes(drug_start_date, avatar_id), colour = "blue", alpha=0.8) +
geom_point(data=dat2, aes(date_of_diagnosis, avatar_id), colour = "purple", alpha=0.3) +
geom_point(data=dat3, aes(bmt_date, avatar_id), colour = "green", alpha=0.3) +
geom_point(data=dat4, aes(rad_start_date, avatar_id), colour = "yellow", alpha=0.3) +
labs(x="all", y=NULL, title="all timeline")
ggp <- ggplot()
ggp +
geom_point(data=dat1, aes(Date_of_Birth, avatar_id, color = "birth"), alpha=0.3) +
geom_point(data=dat5, aes(drug_start_date, avatar_id, colour = "orange", alpha=0.3)) +
geom_point(data=dat2, aes(date_of_diagnosis, avatar_id, colour = "red", alpha=0.3)) +
geom_point(data=dat3, aes(bmt_date, avatar_id, colour = "green", alpha=0.3)) +
geom_point(data=dat4, aes(rad_start_date, avatar_id, colour = "blue", alpha=0.3)) +
labs(x="all", y=NULL, title="all timeline") +
scale_fill_manual(values=c("black", "yellow", "red", "green", "blue"))
############################################################################# Age
colnames(Age_data)
plot_age <- Age_data[, c("avatar_id","Age_at_diagosis", "Age_at_death", "Age_at_lastfollowup","Age_at_firstdrug", "Age_at_firstbmt", "Age_at_firstrad", "Age_at_germcollect")] %>%
pivot_longer(c("Age_at_diagosis", "Age_at_death", "Age_at_lastfollowup","Age_at_firstdrug", "Age_at_firstbmt", "Age_at_firstrad", "Age_at_germcollect"),
names_to = "type", values_to = "age")
ggplot(plot_age, aes(x=age ,y= avatar_id, color = type))+
geom_point(size = 1) +
scale_color_manual(values = c("black", "purple", "green", "blue", "#F0F921FF", "#ED7953FF", "grey"))
labs(x="Age at events", y=NULL, title="Treatment timeline")
############################################################################# Others
library(timevis)
data <- data.frame(
id = "dat1$avatar_id",
content = c("Date_of_Birth", "Date_of_Birth"),
start = c("2013-08-12" , "2015-01-15"),
end = c("2013-08-30" , "2015-01-30")
)
timevis::timevis(data)
data <- data.frame(
id = 1:5,
content = c("Item one" , "Item two" ,"Ranged item", "Item four","fith"),
start = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00", NA),
end = c(NA , NA, "2016-02-04", NA, NA)
)
timevis(data)
#####################################
library("vistime")
# will have to do list...
dat <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
Name = c("Washington", "Adams", "Jefferson", "Adams", "Jefferson", "Burr"),
start = rep(c("1789-03-29", "1797-02-03", "1801-02-03"), 2),
end = rep(c("1797-02-03", "1801-02-03", "1809-02-03"), 2),
color = c('#cbb69d', '#603913', '#c69c6e'),
fontcolor = rep("white", 3))
vistime(dat, events="Position", groups="Name", title="Presidents of the USA")
# as.Date
diag <- Global_data[,c("avatar_id", "date_of_diagnosis_1", "date_of_diagnosis_1")]
diag$diag <- "diagnosis"
drug1 <- Global_data[,c("avatar_id", "drug_start_date_1", "drug_start_date_1")]
drug1$drug <- "drug"
#############################################################################
data <- read.csv(text="event,group,start,end,color
Phase 1,ID1,2016-12-22,2016-12-23,#c8e6c9
Phase 3,ID1,2016-12-29,2017-01-06,#fb8c00
Phase 4,ID1,2017-01-06,2017-02-02,#DD4B39
Room 334,ID2,2016-12-22,2016-12-28,#DEEBF7
Room 335,ID2,2016-12-28,2017-01-05,#C6DBEF
Room 335,ID2,2017-01-05,2017-01-23,#9ECAE1
Phase 2,ID1,2016-12-23,2016-12-29,#a5d6a7
Group 1,ID2,2016-12-22,2016-12-28,#E5F5E0
Group 2,Team 2,2016-12-28,2017-01-23,#C7E9C0
1-217.0,category 2,2016-12-27,2016-12-27,#90caf9
3-200,category 1,2016-12-25,2016-12-25,#1565c0
3-330,category 1,2016-12-25,2016-12-25,#1565c0
3-223,category 1,2016-12-28,2016-12-28,#1565c0
3-225,category 1,2016-12-28,2016-12-28,#1565c0
3-226,category 1,2016-12-28,2016-12-28,#1565c0
3-226,category 1,2017-01-19,2017-01-19,#1565c0
3-330,category 1,2017-01-19,2017-01-19,#1565c0
4-399.7,moon rising,2017-01-13,2017-01-13,#f44336
8-831.0,sundowner drink,2017-01-17,2017-01-17,#8d6e63
9-984.1,birthday party,2016-12-22,2016-12-22,#90a4ae
F01.9,Meetings,2016-12-26,2016-12-26,#e8a735
Z71,Meetings,2017-01-12,2017-01-12,#e8a735
B95.7,Meetings,2017-01-15,2017-01-15,#e8a735
T82.7,Meetings,2017-01-15,2017-01-15,#e8a735")
vistime(data)
##########################################
############# plotty#############################################################################
library(plotly)
df <- read.csv("https://cdn.rawgit.com/plotly/datasets/master/GanttChart-updated.csv",
stringsAsFactors = F)
df$Start <- as.Date(df$Start, format = "%m/%d/%Y")
client <- "Sample Client"
cols <- RColorBrewer::brewer.pal(length(unique(df$Resource)), name = "Set3")
df$color <- factor(df$Resource, labels = cols)
p <- plot_ly()
for(i in 1:(nrow(df) - 1)){
p <- add_trace(p,
x = c(df$Start[i], df$Start[i] + df$Duration[i]),
y = c(i, i),
mode = "lines",
line = list(color = df$color[i], width = 20),
showlegend = F,
hoverinfo = "text",
text = paste("Task: ", df$Task[i], "<br>",
"Duration: ", df$Duration[i], "days<br>",
"Resource: ", df$Resource[i]),
evaluate = T
)
}
p
#############################################################################
bah <- Global_data[(!is.na(Global_data$date_of_diagnosis_1)),]
data <- data.frame(
id = bah$avatar_id,
content = "Age_at_diagosis",
start = bah$date_of_diagnosis_1,
end = NA
)
timevis::timevis(data)
a <- list(names = Tml$avatar_id, level = 1, start = Tml$Age_at_diagosis, end = Tml$Age_at_firstdrug)