-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04 Relative Organ Weights.R
158 lines (134 loc) · 7.96 KB
/
04 Relative Organ Weights.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
library(ggplot2)
library(gridExtra)
library(readxl)
library(patchwork)
setwd("C:/Users/edmondsonef/Desktop/R-plots/")
### Body Weight
my_mean = aggregate(data$Weight, by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$Weight , 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)
### BW Plot
BW <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Body Weight (95% CI)")+#, limits=c(21, 26.5)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.1 , size=0.5) +
geom_jitter(aes(x = Group, y = Weight, color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Brain Weight
my_mean = aggregate(data$'Brain % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Brain % BW' , 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)
### Brain plot
Brain <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Brain (% BW)")+#, limits=c(1.8, 2.3)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$"Brain % BW", color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Heart Weight
my_mean = aggregate(data$'Heart % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Heart % BW' , 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)
### Heart plot
Heart <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Heart (% BW)")+#, limits=c(0.37, 0.56)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$'Heart % BW', color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Liver Weight
my_mean = aggregate(data$'Liver % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Liver % BW' , 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)
### Liver plot
Liver <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Liver (% BW)")+#, limits=c(4, 5.3)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$'Liver % BW', color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Lung Weight
my_mean = aggregate(data$'Lung % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Lung % BW' , 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)
### Lung plot
Lung <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Lung (% BW)")+#, limits=c(0.5, 1.5)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$'Lung % BW', color = `Groups`), width = 0.1)+
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Spleen Weight
my_mean = aggregate(data$'Spleen % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Spleen % BW' , 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)
### Spleen plot
Spleen <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Spleen (% BW)")+#, limits=c(0.04, 0.2)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$'Spleen % BW', color = `Groups`), width = 0.1) +
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Kidney Weight
my_mean = aggregate(data$'Kidney % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Kidney % BW' , 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)
### Kidney plot
Kidney <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Kidney (% BW)")+#, limits=c(0.8, 1.4)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$'Kidney % BW', color = `Groups`), width = 0.1) +
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Graft Weight
my_mean = aggregate(data$'Graft % BW', by=list(data$Group), mean, na.rm = T) ; colnames(my_mean)=c("Group" , "mean")
my_CI = aggregate(data$'Graft % BW' , 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)
### Graft plot
Graft <- ggplot(data) +
geom_point(data = my_info, aes(x = Group , y = mean), color = "grey", size = 2) +
scale_y_continuous(name = "Graft % BW")+#, limits=c(0, 10)) +
geom_errorbar(data = my_info, aes(x = Group, y = CIdiff, ymin = mean - CIdiff, ymax = mean + CIdiff), color = "grey", width = 0.2 , size=0.5) +
geom_jitter(aes(x = Group, y = data$'Graft % BW', color = `Groups`), width = 0.1) +
theme_bw() +
theme(axis.text.x=element_text(angle=25,hjust=1)) +
theme(axis.title.x=element_blank(), text = element_text(size = 10))
### Make multiple plots
tiff("05. Relative Organ Weights.tiff", units="in", width=9, height=10, res=300)
(BW) /
(Brain | Heart) /
(Lung | Kidney) /
(Spleen | Liver) /
plot_layout(guides = "collect") +
plot_annotation(title = "Relative Organ Weights (% of body weight)")
dev.off()
#tiff("05. Relative Organ Weights.tiff", units="in", width=8, height=10, res=300)
#(BW) /
# (Graft | Heart) /
# (Lung | Kidney) /
# (Spleen | Liver) /
# plot_layout(guides = "collect") +
# plot_annotation(title = "Absolute Organ Weights (grams)")
#dev.off()