forked from zacharycompton/cancerAcrossVertebrates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombined_distributions.R
131 lines (96 loc) · 5.5 KB
/
combined_distributions.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
#open libraries
library(patchwork)
library(tidyverse)
library(cowplot)
#read csv
AgeRisk <- read.csv("cleanPath.min20.062822.csv")
#filter for sauropsids
AgeRisk_Sauropsida <- filter(AgeRisk, is.element(Clade, c("Sauropsida")))
AgeRisk_Sauropsida <- filter(AgeRisk_Sauropsida,proportion_lifespan >= 0)
#filter for mammals
AgeRisk_Mammals<- filter(AgeRisk, is.element(Class, c("Mammalia")))
AgeRisk_Mammals <- filter(AgeRisk_Mammals, proportion_lifespan>= 0)
#filter for amphibians
AgeRisk_Amphibia <- filter(AgeRisk, is.element(Class, c("Amphibia")))
AgeRisk_Amphibia <- filter(AgeRisk_Amphibia, proportion_lifespan >= 0)
#Density plot for percentage of age of death for Sauropsids
saur <- ggplot(AgeRisk_Sauropsida, aes(x=proportion_lifespan*100, y=..scaled..,fill=factor((Masspresent)))) +
geom_density(alpha=0.25) +
ggtitle("Sauropsids Neoplasia") +
xlab("Age at Death as a Percentage of Species Lifespan") + ylab("Normalized Frequency") +
coord_cartesian(xlim = c(0,150),ylim = c(0,1))+theme_cowplot(12)+ theme(legend.position = "bottom")+
scale_fill_discrete(name="",labels=c("No Tumor Found", "Tumor Found"))
ggsave("saurage.png",width=13, height=10, limitsize=FALSE,bg="white")
#Density plot for Mammals
mam <- ggplot(AgeRisk_Mammals, aes(x=proportion_lifespan*100, y=..scaled..,fill=factor((Masspresent)))) +
geom_density(alpha=0.25) +
ggtitle("Mammals Neoplasia ") +
xlab("Age at Death as a Percentage of Species Lifespan") + ylab("Normalized Frequency") +
coord_cartesian(xlim = c(0,150),ylim = c(0,1))+theme_cowplot(12)+ theme(legend.position = "bottom")+
scale_fill_discrete(name="",labels=c("No Tumor Found", "Tumor Found"))
ggsave("mammage.png",width=13, height=10, limitsize=FALSE,bg="white")
#Density plot for Amphibians
amph <- ggplot(AgeRisk_Amphibia, aes(x=proportion_lifespan*100, y=..scaled..,fill=factor((Masspresent)))) +
geom_density(alpha=0.25) +
ggtitle("Amphibians Neoplasia") +
xlab("Age at Death as a Percentage of Species Lifespan") + ylab("Normalized Frequency") +
coord_cartesian(xlim = c(0,150),ylim = c(0,1))+theme_cowplot(12)+ theme(legend.position = "bottom")+
scale_fill_discrete(name="",labels=c("No Tumor Found", "Tumor Found"))
ggsave("amphage.png",width=13, height=10, limitsize=FALSE,bg="white")
#create a layout matrix
layout<-"
AA
BB
CC"
#plot all plots onto one image
combo<- mam+saur+amph+plot_layout(design=layout,guides="collect", widths=c(10,10,10)) & theme(legend.position = "bottom")
combo+plot_annotation(caption="Lifespan Data obtained from panTHERIA,which often estimates wild populations\nY axis is probability density")
ggsave("density.pdf",width=5.5, height=9, limitsize=FALSE,bg="white")
#Density plot for percentage of age of death for Sauropsids
AgeRisk <- AgeRisk[,c(14,19,51,52),drop=FALSE]
#used for sanity check
#newAgeRisk<-AgeRisk %>% rowwise() %>%
# mutate(malandneo = sum(c_across(Masspresent:Malignant)))
newAgeRisk<-mutate(AgeRisk, malandneo = ifelse(Malignant == 1, 1,
ifelse(Malignant == -1|Malignant == 0, 0,NA)))
view(newAgeRisk)
AgeRisk_Sauropsida <- filter(newAgeRisk, is.element(Clade, c("Sauropsida")))
AgeRisk_Sauropsida <- filter(AgeRisk_Sauropsida,proportion_lifespan >= 0)
#filter for mammals
AgeRisk_Mammals<- filter(newAgeRisk, is.element(Clade, c("Mammalia")))
AgeRisk_Mammals <- filter(AgeRisk_Mammals, proportion_lifespan>= 0)
#filter for amphibians
AgeRisk_Amphibia <- filter(newAgeRisk, is.element(Clade, c("Amphibia")))
AgeRisk_Amphibia <- filter(AgeRisk_Amphibia, proportion_lifespan >= 0)
saurMal <- ggplot(AgeRisk_Sauropsida, aes(x=proportion_lifespan*100, y=..scaled..,fill=factor((malandneo)))) +
geom_density(alpha=0.25) +
ggtitle("Sauropsids Malignancy") +
xlab("Age at Death as a Percentage of Species Lifespan") + ylab("Normalized Frequency") +
coord_cartesian(xlim = c(0,150),ylim = c(0,1))+theme_cowplot(12)+ theme(legend.position = "bottom")+
scale_fill_discrete(name="",labels=c("No Tumor Found", "Tumor Found"))
#ggsave("saurage.png",width=13, height=10, limitsize=FALSE,bg="white")
#Density plot for Mammals
mamMal <- ggplot(AgeRisk_Mammals, aes(x=proportion_lifespan*100, y=..scaled..,fill=factor((malandneo)))) +
geom_density(alpha=0.25) +
ggtitle("Mammals Malignancy") +
xlab("Age at Death as a Percentage of Species Lifespan") + ylab("Normalized Frequency") +
coord_cartesian(xlim = c(0,150),ylim = c(0,1))+theme_cowplot(12)+ theme(legend.position = "bottom")+
scale_fill_discrete(name="",labels=c("No Tumor Found", "Tumor Found"))
#ggsave("mammage.png",width=13, height=10, limitsize=FALSE,bg="white")
#Density plot for Amphibians
amphMal <- ggplot(AgeRisk_Amphibia, aes(x=proportion_lifespan*100, y=..scaled..,fill=factor((malandneo)))) +
geom_density(alpha=0.25) +
ggtitle("Amphibians Malignancy") +
xlab("Age at Death as a Percentage of Species Lifespan") + ylab("Normalized Frequency") +
coord_cartesian(xlim = c(0,150),ylim = c(0,1))+theme_cowplot(12)+ theme(legend.position = "bottom")+
scale_fill_discrete(name="",labels=c("No Tumor Found", "Tumor Found"))
#ggsave("amphage.png",width=13, height=10, limitsize=FALSE,bg="white")
#create a layout matrix
layout<-"
AADD
BBEE
CCFF"
#plot all plots onto one image
combo<- mam+saur+amph+mamMal+saurMal+amphMal+plot_layout(design=layout,guides="collect", widths=c(10,10,10)) & theme(legend.position = "bottom")
combo+plot_annotation(caption="Lifespan Data obtained from panTHERIA,which often estimates wild populations\nY axis is probability density")
ggsave("Maldensity.pdf",width=11, height=9, limitsize=FALSE,bg="white")