---
title: "Formatting CMR data for adult phenotypic selection"
author: "Amelie Fargevieille"
date: "7/16/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,warning=FALSE)
library("tidyverse",quietly=TRUE)
library("openxlsx",quietly=TRUE)
```

This script intends to create the .txt containing CMR information to test phenotypic selection across years and populations for adults. This should include individuals captured at the start of breeding season (to ensure every individual was born in preceding years and should be ready for breeding season) and should include their SVL the first time they were captured in March, their dewlap area and their body condition (as residuals from the log(mass)~log(SVL) regression).

We don't look for information prior to the first capture in March/April (e.g. some individuals may have been captured the previous year during a trip in May/July/August or October... this should not be included, especially since, there is no way to include this in the CMR). If individuals were captured in subsequent years at another time than March/April, we may indicate they were present in the population in March. For instance, imagine individual X captured in March 2013. Then not encountered in April 2014 but encountered in October 2014: we can say it was present in the population in March 2014 (but unseen). This means our detection probability might be not accurate (at least not reflecting exactly March capture detection). 

Importing data
```{r}
db = read.xlsx("C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/RawData/AnolisDB_06192020.xlsx", sheet = 1, detectDates = TRUE)
```


Selecting variables of interest, selecting sagrei only from Matanzas islands only, selecting only new and recap individuals
```{r}
dbr = db %>%
  dplyr::select(1:6, 8, 9, 13, 16:17, 28)%>%
  filter(Island %in% c("F", "H", "K", "L", "M", "N") & Species %in% "SAGREI") %>%
  mutate(Island = replace(Island, Island == "F", "F4"), 
         Island = replace(Island, Island == "H", "M3"),
         Island = replace(Island, Island == "K", "F2"),
         Island = replace(Island, Island == "L", "M5"),
         Island = replace(Island, Island == "M", "F3"),
         Island = replace(Island, Island == "N", "M4"))
```

Removing individuals with non-confirmed sex

```{r}
dbr = dbr %>%
  filter(!Sex %in% c("?", "M?", "F?", "."))
dbr = dbr %>%
  filter(!is.na(Sex))
dbr$SVL = as.numeric(dbr$SVL)
dbr$Mass = as.numeric(dbr$Mass)
dbr$DlapArea = as.numeric(dbr$DlapArea)
```

```{r}
dbr$Trip=factor(dbr$Trip,c("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"))
```

```{r}
en<-reshape2::dcast(dbr, ID~Trip)
colnames(en)=c("ID","Trip1","Trip2","Trip3","Trip4","Trip5","Trip6","Trip7","Trip8","Trip9","Trip10","Trip11","Trip12","Trip13","Trip14","Trip15","Trip16","Trip17","Trip18","Trip19","Trip20","Trip21","Trip22")
```

Trips corresponding to start of reproductive seasons
Trip 1 (April 2011) = do we include founders?
Trip 3 (April 2012)
Trip 5 (March 2013)
Trip 8 (April 2014)
Trip 11 (March 2015)
Trip 15 (March 2016)
Trip 19 (March 2017)

I need to select every individual that was captured during those trips. I'm not including Trip 19 because I'm not interesting in including individuals first captured during the last year (but I'm interesting in data from individuals recaptured in 2017)

```{r}
en1 = en %>%
 filter_at(vars(Trip1, Trip3, Trip5, Trip8, Trip11, Trip15), any_vars(. == 1))
```

I need to select by "first captured" and to reduce CMR history to keep only 1 capture per year.
Trip 1
```{r}
t1 = filter(en1, Trip1 == 1)
```

I don't need information for Trip 2, then I need to have a function which would be "if any 1 in column Trip 3, Trip 4, then put 1, else put 0" and same thing for other years

```{r}
t1.1 = t1 %>%
  mutate(Y2012 = apply(t1[ , c("Trip3", "Trip4")] == 1, 1, any)) %>%
  mutate(Y2013 = apply(t1[ , c("Trip5", "Trip6", "Trip7")] == 1, 1, any)) %>%
  mutate(Y2014 = apply(t1[ , c("Trip9", "Trip10")] == 1, 1, any)) %>%
  mutate(Y2015 = apply(t1[ , c("Trip12", "Trip13", "Trip14")] == 1, 1, any)) %>%
  mutate(Y2016 = apply(t1[ , c("Trip16", "Trip17", "Trip18")] == 1, 1, any)) %>%
  mutate(Y2017 = apply(t1[ , c("Trip19", "Trip20", "Trip21", "Trip22")] == 1, 1, any)) %>%
  mutate(Y2012, ifelse(Y2012 == TRUE, 1, 0)) %>%
  mutate(Y2013, ifelse(Y2013 == TRUE, 1, 0)) %>%
  mutate(Y2014, ifelse(Y2014 == TRUE, 1, 0)) %>%
  mutate(Y2015, ifelse(Y2015 == TRUE, 1, 0)) %>%
  mutate(Y2016, ifelse(Y2016 == TRUE, 1, 0)) %>%
  mutate(Y2017, ifelse(Y2017 == TRUE, 1, 0)) %>%
  dplyr::select(1:2, 30:35)
colnames(t1.1) = c("ID", "Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017")
```

```{r}
trip1 = filter(dbr, Trip == "1") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
```

```{r}
scale_this <- function(x){
  (x - mean(x, na.rm=TRUE)) / sd(x, na.rm=TRUE)
}
```

```{r}
lm.t1 <- nlme::gls(log(Mass)~log(SVL), na.action = na.omit, data = trip1)
res.t1 <- as.data.frame(lm.t1$residuals)
trip1.2<-cbind(trip1, res.t1[match(rownames(trip1), rownames(res.t1)), ])

trip1.2 <- 
  trip1.2 %>%
  group_by(Sex) %>%
  mutate(SVLst = scale_this(SVL),
         Dlapst = scale_this(DlapArea))

t1.2 = left_join(t1.1, trip1.2, by = "ID")
t1.2$sample = 1
t1.2 = t1.2[ , c(2:8, 17, 9, 10, 15, 16, 14) ]

colnames(t1.2) = c("Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017", "sample", "island", "sex", "svl", "dlap", "bc")
```


Trip 3
```{r}
t3 = en1 %>%
  filter(Trip3 == 1 & Trip1 == 0)
```

```{r}
t3.1 = t3 %>%
  mutate(Y2013 = apply(t3[ , c("Trip5", "Trip6", "Trip7")] == 1, 1, any)) %>%
  mutate(Y2014 = apply(t3[ , c("Trip9", "Trip10")] == 1, 1, any)) %>%
  mutate(Y2015 = apply(t3[ , c("Trip12", "Trip13", "Trip14")] == 1, 1, any)) %>%
  mutate(Y2016 = apply(t3[ , c("Trip16", "Trip17", "Trip18")] == 1, 1, any)) %>%
  mutate(Y2017 = apply(t3[ , c("Trip19", "Trip20", "Trip21", "Trip22")] == 1, 1, any)) %>%
  mutate(Y2013, ifelse(Y2013 == TRUE, 1, 0)) %>%
  mutate(Y2014, ifelse(Y2014 == TRUE, 1, 0)) %>%
  mutate(Y2015, ifelse(Y2015 == TRUE, 1, 0)) %>%
  mutate(Y2016, ifelse(Y2016 == TRUE, 1, 0)) %>%
  mutate(Y2017, ifelse(Y2017 == TRUE, 1, 0)) %>%
  dplyr::select(1:2, 4, 29:33)
colnames(t3.1) = c("ID", "Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017")
```

```{r}
trip3 = filter(dbr, Trip == "3") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
lm.t3 <- nlme::gls(log(Mass)~log(SVL), na.action = na.omit, data = trip3)
res.t3 <- as.data.frame(lm.t3$residuals)
trip3.2<-cbind(trip3, res.t3[match(rownames(trip3), rownames(res.t3)), ])

trip3.2 <- 
  trip3.2 %>%
  group_by(Sex) %>%
  mutate(SVLst = scale_this(SVL),
         Dlapst = scale_this(DlapArea))

t3.2 = left_join(t3.1, trip3.2, by = "ID")
t3.2$sample = 1
t3.2 = t3.2[ , c(2:8, 17, 9, 10, 15, 16, 14) ]

colnames(t3.2) = c("Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017", "sample", "island", "sex", "svl", "dlap", "bc")
```



Trip 5
```{r}
t5 = en1 %>%
  filter(Trip5 == 1) %>%
  filter_at(vars(Trip1, Trip2, Trip3), (all_vars(. == 0)))
```

```{r}
t5.1 = t5 %>%
  mutate(Y2014 = apply(t5[ , c("Trip9", "Trip10")] == 1, 1, any)) %>%
  mutate(Y2015 = apply(t5[ , c("Trip12", "Trip13", "Trip14")] == 1, 1, any)) %>%
  mutate(Y2016 = apply(t5[ , c("Trip16", "Trip17", "Trip18")] == 1, 1, any)) %>%
  mutate(Y2017 = apply(t5[ , c("Trip19", "Trip20", "Trip21", "Trip22")] == 1, 1, any)) %>%
  mutate(Y2014, ifelse(Y2014 == TRUE, 1, 0)) %>%
  mutate(Y2015, ifelse(Y2015 == TRUE, 1, 0)) %>%
  mutate(Y2016, ifelse(Y2016 == TRUE, 1, 0)) %>%
  mutate(Y2017, ifelse(Y2017 == TRUE, 1, 0)) %>%
  dplyr::select(1:2, 4, 6, 28:31)
colnames(t5.1) = c("ID", "Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017")
```

```{r}
trip5 = filter(dbr, Trip == "5") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
lm.t5 <- nlme::gls(log(Mass)~log(SVL), na.action = na.omit, data = trip5)
res.t5 <- as.data.frame(lm.t5$residuals)
trip5.2<-cbind(trip5, res.t5[match(rownames(trip5), rownames(res.t5)), ])

trip5.2 <- 
  trip5.2 %>%
  group_by(Sex) %>%
  mutate(SVLst = scale_this(SVL),
         Dlapst = scale_this(DlapArea))

t5.2 = left_join(t5.1, trip5.2, by = "ID")
t5.2$sample = 1
t5.2 = t5.2[ , c(2:8, 17, 9, 10, 15, 16, 14) ]

colnames(t5.2) = c("Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017", "sample", "island", "sex", "svl", "dlap", "bc")
```


Trip 8
```{r}
t8 = en1 %>%
  filter(Trip8 == 1) %>%
  filter_at(vars(Trip1, Trip2, Trip3, Trip4, Trip5), (all_vars(. == 0)))
```

```{r}
t8.1 = t8 %>%
  mutate(Y2015 = apply(t8[ , c("Trip12", "Trip13", "Trip14")] == 1, 1, any)) %>%
  mutate(Y2016 = apply(t8[ , c("Trip16", "Trip17", "Trip18")] == 1, 1, any)) %>%
  mutate(Y2017 = apply(t8[ , c("Trip19", "Trip20", "Trip21", "Trip22")] == 1, 1, any)) %>%
  mutate(Y2015, ifelse(Y2015 == TRUE, 1, 0)) %>%
  mutate(Y2016, ifelse(Y2016 == TRUE, 1, 0)) %>%
  mutate(Y2017, ifelse(Y2017 == TRUE, 1, 0)) %>%
  dplyr::select(1:2, 4, 6, 9, 27:29)
colnames(t8.1) = c("ID", "Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017")
```

```{r}
trip8 = filter(dbr, Trip == "8") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
lm.t8 <- nlme::gls(log(Mass)~log(SVL), na.action = na.omit, data = trip8)
res.t8 <- as.data.frame(lm.t8$residuals)
trip8.2<-cbind(trip8, res.t8[match(rownames(trip8), rownames(res.t8)), ])

trip8.2 <- 
  trip8.2 %>%
  group_by(Sex) %>%
  mutate(SVLst = scale_this(SVL),
         Dlapst = scale_this(DlapArea))

t8.2 = left_join(t8.1, trip8.2, by = "ID")
t8.2$sample = 1
t8.2 = t8.2[ , c(2:8, 17, 9, 10, 15, 16, 14) ]

colnames(t8.2) = c("Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017", "sample", "island", "sex", "svl", "dlap", "bc")
```


Trip 11
```{r}
t11 = en1 %>%
  filter(Trip11 == 1) %>%
  filter_at(vars(Trip1, Trip2, Trip3, Trip4, Trip5, Trip6, Trip7, Trip8), (all_vars(. == 0)))
```

```{r}
t11.1 = t11 %>%
  mutate(Y2016 = apply(t11[ , c("Trip16", "Trip17", "Trip18")] == 1, 1, any)) %>%
  mutate(Y2017 = apply(t11[ , c("Trip19", "Trip20", "Trip21", "Trip22")] == 1, 1, any)) %>%
  mutate(Y2016, ifelse(Y2016 == TRUE, 1, 0)) %>%
  mutate(Y2017, ifelse(Y2017 == TRUE, 1, 0)) %>%
  dplyr::select(1:2, 4, 6, 9, 12, 26, 27)
colnames(t11.1) = c("ID", "Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017")
```

```{r}
trip11 = filter(dbr, Trip == "11") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
lm.t11 <- nlme::gls(log(Mass)~log(SVL), na.action = na.omit, data = trip11)
res.t11 <- as.data.frame(lm.t11$residuals)
trip11.2<-cbind(trip11, res.t11[match(rownames(trip11), rownames(res.t11)), ])

trip11.2 <- 
  trip11.2 %>%
  group_by(Sex) %>%
  mutate(SVLst = scale_this(SVL),
         Dlapst = scale_this(DlapArea))

t11.2 = left_join(t11.1, trip11.2, by = "ID")
t11.2$sample = 1
t11.2 = t11.2[ , c(2:8, 17, 9, 10, 15, 16, 14) ]

colnames(t11.2) = c("Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017", "sample", "island", "sex", "svl", "dlap", "bc")
```



Trip 15
```{r}
t15 = en1 %>%
  filter(Trip15 == 1) %>%
  filter_at(vars(Trip1, Trip2, Trip3, Trip4, Trip5, Trip6, Trip7, Trip8, Trip9, Trip10, Trip11, Trip12), (all_vars(. == 0)))
```

```{r}
t15.1 = t15 %>%
  mutate(Y2017 = apply(t15[ , c("Trip19", "Trip20", "Trip21", "Trip22")] == 1, 1, any)) %>%
  mutate(Y2017, ifelse(Y2017 == TRUE, 1, 0)) %>%
  dplyr::select(1:2, 4, 6, 9, 12, 16, 25)
colnames(t15.1) = c("ID", "Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017")
```

```{r}
trip15 = filter(dbr, Trip == "15") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
lm.t15 <- nlme::gls(log(Mass)~log(SVL), na.action = na.omit, data = trip15)
res.t15 <- as.data.frame(lm.t15$residuals)
trip15.2<-cbind(trip15, res.t15[match(rownames(trip15), rownames(res.t15)), ])

trip15.2 <- 
  trip15.2 %>%
  group_by(Sex) %>%
  mutate(SVLst = scale_this(SVL),
         Dlapst = scale_this(DlapArea))

t15.2 = left_join(t15.1, trip15.2, by = "ID")
t15.2$sample = 1
t15.2 = t15.2[ , c(2:8, 17, 9, 10, 15, 16, 14) ]

colnames(t15.2) = c("Y2011", "Y2012", "Y2013", "Y2014", "Y2015", "Y2016", "Y2017", "sample", "island", "sex", "svl", "dlap", "bc")
```

```{r}
ad = do.call("rbind", list(t1.2, t3.2, t5.2, t8.2, t11.2, t15.2))
```



Before saving the file, I need to see how many individuals there are per trip and per island (some islands have not been monitored the whole time)

```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2011)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2011)
```


```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2012)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2012)
```

```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2013)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2013)
```

```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2014)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2014)
```

```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2015)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2015)
```

```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2016)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2016)
```

```{r}
table(ad[ad$sex == "M", ]$island, ad[ad$sex == "M", ]$Y2017)
table(ad[ad$sex == "F", ]$island, ad[ad$sex == "F", ]$Y2017)
```


```{r}
table(t1.2[t1.2$sex == "M", ]$island, t1.2[ t1.2$sex == "M", ]$Y2011)
table(t1.2[t1.2$sex == "F", ]$island, t1.2[ t1.2$sex == "F", ]$Y2011)
```
```{r}
table(t3.2[t3.2$sex == "M", ]$island, t3.2[ t3.2$sex == "M", ]$Y2012)
table(t3.2[t3.2$sex == "F", ]$island, t3.2[ t3.2$sex == "F", ]$Y2012)
```
```{r}
table(t5.2[t5.2$sex == "M", ]$island, t5.2[ t5.2$sex == "M", ]$Y2013)
table(t5.2[t5.2$sex == "F", ]$island, t5.2[ t5.2$sex == "F", ]$Y2013)
```



```{r}
table(t8.2[t8.2$sex == "M", ]$island, t8.2[ t8.2$sex == "M", ]$Y2014)
table(t8.2[t8.2$sex == "F", ]$island, t8.2[ t8.2$sex == "F", ]$Y2014)
```

```{r}
table(t11.2[t11.2$sex == "M", ]$island, t11.2[ t11.2$sex == "M", ]$Y2015)
table(t11.2[t11.2$sex == "F", ]$island, t11.2[ t11.2$sex == "F", ]$Y2015)
```

```{r}
table(t15.2[t15.2$sex == "M", ]$island, t15.2[ t15.2$sex == "M", ]$Y2016)
table(t15.2[t15.2$sex == "F", ]$island, t15.2[ t15.2$sex == "F", ]$Y2016)
```
I need to divide the final file in two different files, since sampling on islands M4 and M5 stopped in 2015 and F3 in 2016
```{r}
adLMN = ad %>%
  filter(island %in% c("M4", "M5", "F3")) %>%
  dplyr::select(c(1:4, 8:11, 13))
adFKH = ad %>%
  filter(island %in% c("F4", "F2", "M3")) %>%
  dplyr::select(c(1:11, 13))
```

Renaming files to fit CMR format then saving files in .txt
```{r}
colnames(adLMN) = c("H:Y2011", "H:Y2012", "H:Y2013", "H:Y2014", "S:sample", "$COV:island", "$COV:sex", "COV:SVL", "COV:BC")
colnames(adFKH) = c("H:Y2011", "H:Y2012", "H:Y2013", "H:Y2014", "H:Y2015", "H:Y2016", "H:Y2017", "S:sample", "$COV:island", "$COV:sex", "COV:SVL", "COV:BC")
adLMN = na.omit(adLMN)
adFKH = na.omit(adFKH)
write.table(adLMN, "C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/ad_LMN.txt", sep = "\t", quote = FALSE, col.names = TRUE, row.names = FALSE) 
write.table(adFKH, "C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/ad_FHK.txt", sep = "\t", quote = FALSE, col.names = TRUE, row.names = FALSE) 
```

there is an issue with the file for LMN islands. It is potentially 10 rows with 0000
```{r}
filter_at(adLMN, c(1:4), all_vars(. == "0"))
```

It is likely individuals captured in 2015 on F3. I can select all individuals which have at least a "1")
```{r}
adLMN2 = adLMN %>%
  filter_at(c(1:4), any_vars(. == "1"))
write.table(adLMN2, "C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/ad_LMN.txt", sep = "\t", quote = FALSE, col.names = TRUE, row.names = FALSE) 
```


#File with dewlap area
I first need to only select males and omit NAs in dewlap column
```{r}
dlap = ad %>%
  filter(sex == "M") %>%
  filter(!is.na(dlap))
```

Only two individuals with dewlap  information in Y2011. I need to remove those individuals as well as the column Y2011.
```{r}
dlap = dlap %>%
  filter(Y2011 == "0") %>%
  dplyr::select(2:12)
```

Before separating files, I need to tally the number of individuals 
```{r}
table(dlap$island, dlap$Y2012)
```
```{r}
table(dlap$island, dlap$Y2013)
```

```{r}
table(dlap$island, dlap$Y2014)
```

```{r}
table(dlap$island, dlap$Y2015)
```

```{r}
table(dlap$island, dlap$Y2016)
```
```{r}
table(dlap$island, dlap$Y2017)
```
```{r}
t3.2 %>%
  filter(!is.na(dlap) & sex == "M") %>%
  group_by(island) %>%
  summarise(n = n())
```
```{r}
t5.2 %>%
  filter(!is.na(dlap) & sex == "M") %>%
  group_by(island) %>%
  summarise(n = n())
```
```{r}
t8.2 %>%
  filter(!is.na(dlap) & sex == "M") %>%
  group_by(island) %>%
  summarise(n = n())
```


```{r}
t11.2 %>%
  filter(!is.na(dlap) & sex == "M") %>%
  group_by(island) %>%
  summarise(n = n())
```


```{r}
t15.2 %>%
  filter(!is.na(dlap) & sex == "M") %>%
  group_by(island) %>%
  summarise(n = n())
```


```{r}
dlapLMN = dlap %>%
  filter(island %in% c("M4", "M5", "F3")) %>%
  dplyr::select(c(1:3, 7:11))
dlapFKH = dlap %>%
  filter(island %in% c("F4", "F2", "M3")) 
```


```{r}
filter_at(dlapLMN, c(1:3), all_vars(. == "0"))
```

It is likely individuals captured in 2015 on F3. I can select all individuals which have at least a "1")
```{r}

```



Renaming files to fit CMR format then saving files in .txt
```{r}
colnames(dlapLMN) = c("H:Y2012", "H:Y2013", "H:Y2014", "S:sample", "$COV:island", "$COV:sex", "COV:SVL", "COV:dlap")
colnames(dlapFKH) = c("H:Y2012", "H:Y2013", "H:Y2014", "H:Y2015", "H:Y2016", "H:Y2017", "S:sample", "$COV:island", "$COV:sex", "COV:SVL", "COV:dlap")
dlapLMN = na.omit(dlapLMN)
dlapFKH = na.omit(dlapFKH)
dlapLMN = dlapLMN %>%
  filter_at(c(1:3), any_vars(. == "1"))
write.table(dlapLMN, "C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/dlap_LMN.txt", sep = "\t", quote = FALSE, col.names = TRUE, row.names = FALSE) 
write.table(dlapFKH, "C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/dlap_FHK.txt", sep = "\t", quote = FALSE, col.names = TRUE, row.names = FALSE) 
```


###SVL, mass, dewlap distribution


I may need to select any individual in March/April, May + >34/39 in July/August to see if distribution is similar.

May trip (+ March 2017)
```{r}
trip12 = filter(dbr, Trip == "12") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip16 = filter(dbr, Trip == "16") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip20 = filter(dbr, Trip == "20") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip19 = filter(dbr, Trip == "19") %>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
```

July/August trip (filtering for >34/39mm)
```{r}
trip2 = filter(dbr, Trip == "2") %>%
  filter(if(Sex == "M") SVL >= 39 else SVL >=34)%>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip6 = filter(dbr, Trip == "6") %>%
  filter(if(Sex == "M") SVL >= 39 else SVL >=34)%>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip9 = filter(dbr, Trip == "9") %>%
  filter(if(Sex == "M") SVL >= 39 else SVL >=34)%>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip13 = filter(dbr, Trip == "13") %>%
  filter(if(Sex == "M") SVL >= 39 else SVL >=34)%>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip17 = filter(dbr, Trip == "17") %>%
  filter(if(Sex == "M") SVL >= 39 else SVL >=34)%>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
trip21 = filter(dbr, Trip == "21") %>%
  filter(if(Sex == "M") SVL >= 39 else SVL >=34)%>%
  dplyr::select(ID, Island, Sex, SVL, Mass, DlapArea)
```



```{r}
svlall = ggplot(ad, aes(x = SVL)) + 
  geom_density() +
  labs(title = "All trips") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl1 = ggplot(trip1, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 1") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl2 = ggplot(trip2, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 2") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl3 = ggplot(trip3, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 3") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r}
svl5 = ggplot(trip5, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 5") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl6 = ggplot(trip6, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 6") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl8 = ggplot(trip8, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 8") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl9 = ggplot(trip9, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 9") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r}
svl11 = ggplot(trip11, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 11") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl12 = ggplot(trip12, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 12") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl13 = ggplot(trip13, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 13") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl15 = ggplot(trip15, aes(x = SVL)) + geom_density() + 
  labs(title = "Trip 15") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl16 = ggplot(trip16, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 16") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl17 = ggplot(trip17, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 17") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl19 = ggplot(trip19, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 19") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl20 = ggplot(trip20, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 20") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
svl20
```

```{r}
svl21 = ggplot(trip21, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 21") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r fig.width = 15, fig.height = 25, fig.align = "center"}
library(cowplot)
plot_svl = ggdraw() +
  draw_plot(svl1, x = 0, y = 0.86, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl3, x = 0, y = 0.72, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl5, x = 0, y = 0.58, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl8, x = 0, y = 0.44, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl11, x = 0, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl15, x = 0, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl19, x = 0, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl12, x = 0.33, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl16, x = 0.33, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl20, x = 0.33, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl2, x = 0.67, y = 0.86, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl6, x = 0.67, y = 0.58, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl9, x = 0.67, y = 0.44, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl13, x = 0.67, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl17, x = 0.67, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl21, x = 0.67, y = 0.04, width = 0.32, height = 0.12, hjust = 0) 

plot_svl
```



```{r}
svlall = ggplot(ad, aes(x = SVL)) + 
  geom_density() +
  labs(title = "All trips") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl1 = ggplot(trip1, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 1") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl2 = ggplot(trip2, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 2") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl3 = ggplot(trip3, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 3") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r}
svl5 = ggplot(trip5, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 5") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl6 = ggplot(trip6, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 6") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl8 = ggplot(trip8, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 8") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl9 = ggplot(trip9, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 9") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r}
svl11 = ggplot(trip11, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 11") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl12 = ggplot(trip12, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 12") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl13 = ggplot(trip13, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 13") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl15 = ggplot(trip15, aes(x = SVL)) + geom_density() + 
  labs(title = "Trip 15") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl16 = ggplot(trip16, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 16") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl17 = ggplot(trip17, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 17") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl19 = ggplot(trip19, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 19") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
svl20 = ggplot(trip20, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 20") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
svl20
```

```{r}
svl21 = ggplot(trip21, aes(x = SVL)) + geom_density() +
  labs(title = "Trip 21") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "SVL", limits = c(15, 80), breaks = seq(20, 70, 10)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r fig.width = 15, fig.height = 25, fig.align = "center"}
library(cowplot)
plot_svl = ggdraw() +
  draw_plot(svl1, x = 0, y = 0.86, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl3, x = 0, y = 0.72, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl5, x = 0, y = 0.58, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl8, x = 0, y = 0.44, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl11, x = 0, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl15, x = 0, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl19, x = 0, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl12, x = 0.33, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl16, x = 0.33, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl20, x = 0.33, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl2, x = 0.67, y = 0.86, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl6, x = 0.67, y = 0.58, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl9, x = 0.67, y = 0.44, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl13, x = 0.67, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl17, x = 0.67, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(svl21, x = 0.67, y = 0.04, width = 0.32, height = 0.12, hjust = 0) 
save_plot("C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/SVL_distribution.png", plot_svl, ncol = 1, nrow = 1, base_height = 15, base_width = 15)
```


#mass

```{r}
mass1 = ggplot(trip1, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 1") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass2 = ggplot(trip2, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 2") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass3 = ggplot(trip3, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 3") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r}
mass5 = ggplot(trip5, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 5") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass6 = ggplot(trip6, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 6") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass8 = ggplot(trip8, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 8") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass9 = ggplot(trip9, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 9") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r}
mass11 = ggplot(trip11, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 11") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass12 = ggplot(trip12, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 12") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass13 = ggplot(trip13, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 13") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass15 = ggplot(trip15, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 15") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass16 = ggplot(trip16, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 16") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass17 = ggplot(trip17, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 17") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass19 = ggplot(trip19, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 19") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```

```{r}
mass20 = ggplot(trip20, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 20") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
mass20
```

```{r}
mass21 = ggplot(trip21, aes(x = Mass)) + geom_density() +
  labs(title = "Trip 21") +
  facet_wrap(. ~ Sex, labeller = labeller(Sex = c("F" = "Female", "M" = "Male"))) +
  scale_x_continuous(name = "Mass", limits = c(0, 10), breaks = seq(0, 10, 2)) +  
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
```


```{r fig.width = 15, fig.height = 25, fig.align = "center"}
plot_mass = ggdraw() +
  draw_plot(mass1, x = 0, y = 0.86, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass3, x = 0, y = 0.72, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass5, x = 0, y = 0.58, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass8, x = 0, y = 0.44, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass11, x = 0, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass15, x = 0, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass19, x = 0, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass12, x = 0.33, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass16, x = 0.33, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass20, x = 0.33, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass2, x = 0.67, y = 0.86, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass6, x = 0.67, y = 0.58, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass9, x = 0.67, y = 0.44, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass13, x = 0.67, y = 0.32, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass17, x = 0.67, y = 0.18, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(mass21, x = 0.67, y = 0.04, width = 0.32, height = 0.12, hjust = 0) 
save_plot("C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/mass_distribution.png", plot_mass, ncol = 1, nrow = 1, base_height = 15, base_width = 15)
```





#dewlap


```{r}
dlap3 = ggplot(filter(trip3, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 3") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap3
```


```{r}
dlap5 = ggplot(filter(trip5, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 5") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap5
```


```{r}
dlap8 = ggplot(filter(trip8, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 8") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap8
```

```{r}
dlap9 = ggplot(filter(trip9, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 9") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap9
```


```{r}
dlap11 = ggplot(filter(trip11, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 11") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap11
```



```{r}
dlap15 = ggplot(filter(trip15, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 15") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap15
```

```{r}
dlap16 = ggplot(filter(trip16, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 16") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap16
```

```{r}
dlap17 = ggplot(filter(trip17, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 17") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap17
```

```{r}
dlap19 = ggplot(filter(trip19, Sex == "M"), aes(x = DlapArea)) + geom_density() +
  labs(title = "Trip 19") +
  scale_x_continuous(name = "Dewlap area", limits = c(0, 500), breaks = seq(0, 500, 50)) +
  theme(plot.margin = margin(t = 0.25, b = 0.25, r = 0.25, l = 0.25, "cm"),
        plot.title = element_text(size = 16, color = "black", family = "Arial", hjust = 0.5),
        panel.background=element_blank(),
        panel.border = element_blank(),
        panel.grid = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 12, color = "black", family = "Arial", face = "bold"),
        text = element_text(size=10,color="black", family = "Arial"),
        axis.line = element_line(color = "black", size = 0.5),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_line(color = "black", size = 0.5),
        axis.text.x = element_text(size=10, color="black", family = "Arial"),
        axis.text.y = element_text(size=10, color="black", family = "Arial"),
        axis.title.y = element_text(size=12, color="black", family = "Arial"),
        legend.position = c(0.9, 0.9),
        legend.justification = c(0.5, 0.5),
        legend.box.background = element_rect(color = "transparent", fill = "transparent"),
        legend.box.margin = margin(t = 0.25, r =0.25, b = 0.25, l = 0.25, unit = "cm"),
        legend.key = element_blank())
dlap19
```




```{r fig.width = 15, fig.height = 25, fig.align = "center"}
plot_dlap = ggdraw() +
  draw_plot(dlap3, x = 0, y = 0.84, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap5, x = 0, y = 0.68, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap8, x = 0, y = 0.52, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap11, x = 0, y = 0.36, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap15, x = 0, y = 0.20, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap19, x = 0, y = 0.04, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap16, x = 0.33, y = 0.20, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap9, x = 0.67, y = 0.36, width = 0.32, height = 0.12, hjust = 0) +
  draw_plot(dlap17, x = 0.67, y = 0.20, width = 0.32, height = 0.12, hjust = 0)
save_plot("C:/Users/akf0020/OneDrive - Auburn University/PhenotypicSelection/CMR/dewlap_distribution.png", plot_dlap, ncol = 1, nrow = 1, base_height = 15, base_width = 15)
```




