-
Notifications
You must be signed in to change notification settings - Fork 0
/
02 Boxplot CHEM.R
364 lines (321 loc) · 18.4 KB
/
02 Boxplot CHEM.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#data<-MHL_19_331_121_Efficacy <- read_excel("C:/Users/edmondsonef/Desktop/MHL 19-331-121 Efficacy.xlsx", sheet = "plot")
library(ggplot2)
library(gridExtra)
library(readxl)
library(ggpubr)
setwd("C:/Users/edmondsonef/Desktop/R-plots/")
###Generate Data
### Albulmin:Globulin Ratio
data<-dplyr:: mutate(data, AGR = (ALB/(TP-ALB)))
my_mean = aggregate(data$AGR, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$AGR , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
#my_info$ref.low = c()
#my_info$ref.hi = c()
### AGR Plot
ymxAGR = max(data$AGR, na.rm = T)
yminAGR = min(data$AGR, na.rm = T)
AGR <- ggplot(data) +
scale_y_continuous(name = "Albumin:Globulin", limits=c(yminAGR*.98, ymxAGR*1.02)) +
#geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = AGR, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### BUN:Creatinine Ratio
data<-dplyr:: mutate(data, BCR = (BUN/CRE))
my_mean = aggregate(data$BCR, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$BCR , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
#my_info$ref.low = c()
#my_info$ref.hi = c()
### BCR Plot
ymxBCR = max(data$BCR, na.rm = T)
yminBCR = min(data$BCR, na.rm = T)
BCR <- ggplot(data) +
scale_y_continuous(name = "BUN:Creatinine", limits=c(yminBCR*.98, ymxBCR*1.02)) +
#geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = BCR, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### ALB
my_mean = aggregate(data$ALB, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$ALB , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(2.77)
my_info$ref.hi = c(4.8)
### ALB Plot
ymxALB = max(data$ALB, na.rm = T)
yminALB = min(data$ALB, na.rm = T)
ALB <- ggplot(data) +
scale_y_continuous(name = "Albumin", limits=c(yminALB*.98, ymxALB*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = ALB, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### ALP
my_mean = aggregate(data$ALP, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$ALP , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(41)
my_info$ref.hi = c(190)
### ALP plot
ymxALP = max(data$ALP, na.rm = T)
yminALP = min(data$ALP, na.rm = T)
ALP <- ggplot(data) +
scale_y_continuous(name = "ALP", limits=c(yminALP*.98, ymxALP*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = ALP, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### ALT
my_mean = aggregate(data$ALT, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$ALT , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(21)
my_info$ref.hi = c(168)
### ALT plot
ymxALT = max(data$ALT, na.rm = T)
yminALT = min(data$ALT, na.rm = T)
ALT <- ggplot(data) +
scale_y_continuous(name = "ALT", limits=c(yminALT*.98, ymxALT*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = ALT, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### BUN
my_mean = aggregate(data$BUN, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$BUN , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(10.7)
my_info$ref.hi = c(34.2)
### BUN plot
ymxBUN = max(data$BUN, na.rm = T)
yminBUN = min(data$BUN, na.rm = T)
BUN <- ggplot(data) +
scale_y_continuous(name = "BUN", limits=c(yminBUN*.98, ymxBUN*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = BUN, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### CREATININE
my_mean = aggregate(data$CRE, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$CRE , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(0.2)
my_info$ref.hi = c(0.5)
### CREATININE plot
ymxCRE = max(data$CRE, na.rm = T)
yminCRE = min(data$CRE, na.rm = T)
CRE <- ggplot(data) +
scale_y_continuous(name = "Creatinine", limits=c(yminCRE*.8, ymxCRE*1.2)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = CRE, shape = Sex, color = `Groups`), height = 0.001, width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### GLU
my_mean = aggregate(data$GLU, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$GLU , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(115)
my_info$ref.hi = c(292)
### GLU plot
ymxGLU = max(data$GLU, na.rm = T)
yminGLU = min(data$GLU, na.rm = T)
GLU <- ggplot(data) +
scale_y_continuous(name = "GLU", limits=c(yminGLU*.98, ymxGLU*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = GLU, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### TP
my_mean = aggregate(data$TP, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$TP , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(4.6)
my_info$ref.hi = c(6.6)
### TP plot
ymxTP = max(data$TP, na.rm = T)
yminTP = min(data$TP, na.rm = T)
TP <- ggplot(data) +
scale_y_continuous(name = "Total Protein", limits=c(yminTP*.98, ymxTP*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = TP, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### GLOB
my_mean = aggregate(data$GLOB, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$GLOB , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(0.5)
my_info$ref.hi = c(3.1)
### GLOB plot
ymxGLOB = max(data$GLOB, na.rm = T)
yminGLOB = min(data$GLOB, na.rm = T)
GLOB <- ggplot(data) +
scale_y_continuous(name = "GLOB", limits=c(yminGLOB*.98, ymxGLOB*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = GLOB, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### Ca
my_mean = aggregate(data$Ca, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$Ca , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(9.77)
my_info$ref.hi = c(12.2)
### Ca plot
ymxCa = max(data$Ca, na.rm = T)
yminCa = min(data$Ca, na.rm = T)
Ca <- ggplot(data) +
scale_y_continuous(name = "Ca2+", limits=c(yminCa*.98, ymxCa*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = Ca, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### PHOS
my_mean = aggregate(data$PHOS, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$PHOS , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(9.1)
my_info$ref.hi = c(13.1)
### PHOS plot
ymxPHOS = max(data$PHOS, na.rm = T)
yminPHOS = min(data$PHOS, na.rm = T)
PHOS <- ggplot(data) +
scale_y_continuous(name = "PHOS", limits=c(yminPHOS*.98, ymxPHOS*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = PHOS, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### NaPlus
my_mean = aggregate(data$`Na Plus`, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$`Na Plus`, by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(124)
my_info$ref.hi = c(174)
### NaPlus plot
ymxNa = max(data$`Na Plus`, na.rm = T)
yminNa = min(data$`Na Plus`, na.rm = T)
NaPlus <- ggplot(data) +
scale_y_continuous(name = "Na+", limits=c(yminNa*.98, ymxNa*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = `Na Plus`, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### KPlus
my_mean = aggregate(data$KPlus, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$KPlus , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(6)
my_info$ref.hi = c(11.8)
### KPlus plot
ymxKPlus = max(data$KPlus, na.rm = T)
yminKPlus = min(data$KPlus, na.rm = T)
KPlus <- ggplot(data) +
scale_y_continuous(name = "K+", limits=c(yminKPlus*.98, ymxKPlus*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = KPlus, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### TBIL
my_mean = aggregate(data$TBIL, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$TBIL , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(0.1)
my_info$ref.hi = c(0.6)
### TBIL plot
ymxTBIL = max(data$TBIL, na.rm = T)
yminTBIL = min(data$TBIL, na.rm = T)
TBIL <- ggplot(data) +
scale_y_continuous(name = "TBIL", limits=c(yminTBIL*.98, ymxTBIL*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = TBIL, shape = Sex, color = `Groups`), width = 0.1, height = 0.001)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
### AMY
my_mean = aggregate(data$AMY, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$AMY , by=list(data$Group) , FUN = function(x) t.test(x)$conf.int) ; colnames(my_CI)=c("Group" , "CI")
my_info = merge(my_mean , my_CI , by.x=1 , by.y=1)
my_info$CIdiff = ((my_CI$CI[,2] - my_CI$CI[,1])/2)
my_info$ref.low = c(200)
my_info$ref.hi = c(1200)
### AMY plot
ymxAMY = max(data$AMY, na.rm = T)
yminAMY = min(data$AMY, na.rm = T)
AMY <- ggplot(data) +
scale_y_continuous(name = "AMY", limits=c(yminAMY*.98, ymxAMY*1.02)) +
geom_errorbar(data = my_info, aes(x = Group, ymin = ref.low, ymax = ref.hi), color = "#f5f5f5", width = 0, size=10) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "#a9a9a9", size = 1.5) +
#geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "#a9a9a9", width = 0.2 , size=0.7) +
geom_jitter(aes(x = Group, y = AMY, shape = Sex, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank())
tiff("Clinical Chemistry.tiff", units="in", width=13, height=7, res=200)
(TP | ALB | GLOB | AGR) /
(BUN | CRE | BCR | GLU) /
(Ca | PHOS | KPlus | NaPlus) /
(ALP | ALT | TBIL | AMY) /
plot_layout(guides = "collect") +
plot_annotation(title = "Clinical Chemistry")
dev.off()