---
title: "R Notebook"
output: html_notebook
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Cmd+Shift+Enter*.
```{r}
require("gdata")
require("car")
require("ggplot2")
require("plyr")
require('dplyr')
require("lsmeans")
#require("mgcv")
#require("nlme")
#require("AICcmodavg")
require("multcompView")
require("tidyr")
require("stringr")
require ("lme4")
require ( "gridExtra")
library("MASS")
require ("ggiraphExtra")
require ("compute.es")
require ("effects")
require ("multcomp")
require ("pastecs")
require ("WRS")
library("readr")
```
```{r}
Cor<- read_csv ("Correlation_devtime_wingarea.csv")
Cor
head (Cor)
Cor$Line <- as.factor(Cor$Line)
Cor$Temp <- as.factor(Cor$Temp)
Cor$PL <- as.factor(Cor$PL)
#THE DATASET IS MADE WITH INDIV wing area OF EACH female adult, BUT MEAN dev time OF egg to adult PER TREATMENT averaging replicates.
```
```{r}
install.packages("ggpubr")
require ("ggpubr")
library("ggpubr")
#overall correlation between two traits
cor1 <- cor (Cor$Dev_time, Cor$Wing_area)
cor1
mod1 <- cor.test(Cor$Wing_area, Cor$Dev_time, method = c("pearson", "kendall", "spearman"))
mod1
mod2 <- cor.test(Cor$Wing_area, Cor$Dev_time, method = c( "kendall"))
mod2
mod3 <- cor.test(Cor$Wing_area, Cor$Dev_time, method = c("spearman"))
mod3
cor.lm <- lm (Wing_area ~ Dev_time * Line, data = Cor)
summary (cor.lm)
car::Anova(cor.lm)
```
```{r}
#correlation across five lines
Line21 <- Cor[which(Cor$Line=="21"), ]
head (Line21)
cor21 <- cor.test (Line21$Wing_area, Line21$Dev_time, method = c("pearson"))
cor21
#not significant
Line36 <- Cor[which(Cor$Line=="36"), ]
head (Line36)
cor36 <- cor.test (Line36$Wing_area, Line36$Dev_time, method = c("pearson"))
cor36
#significant
Line56 <- Cor[which(Cor$Line=="56"), ]
head (Line56)
cor56 <- cor.test (Line56$Wing_area, Line56$Dev_time, method = c("pearson"))
cor56
#significant
Line63 <- Cor[which(Cor$Line=="63"), ]
head (Line63)
cor63 <- cor.test (Line63$Wing_area, Line63$Dev_time, method = c("pearson"))
cor63
#not significant
Line85 <- Cor[which(Cor$Line=="85"), ]
head (Line85)
cor85 <- cor.test (Line85$Wing_area, Line85$Dev_time, method = c("pearson"))
cor85
#not significant
```
```{r}
#correlation across five lines at two temps separately
Line21_25 <- Cor[which(Cor$Line=="21" & Cor$Temp=="25"), ]
head (Line21_25)
cor21_25 <- cor.test (Line21_25$Wing_area, Line21_25$Dev_time, method = c("pearson"))
cor21_25
#significant
Line21_28 <- Cor[which(Cor$Line=="21" & Cor$Temp=="28"), ]
head (Line21_28)
cor21_28 <- cor.test (Line21_28$Wing_area, Line21_28$Dev_time, method = c("pearson"))
cor21_28
Line36_25 <- Cor[which(Cor$Line=="36" & Cor$Temp=="25"), ]
head (Line36_25)
cor36_25 <- cor.test (Line36_25$Wing_area, Line36_25$Dev_time, method = c("pearson"))
cor36_25
#significant
Line36_28 <- Cor[which(Cor$Line=="36" & Cor$Temp=="28"), ]
head (Line36_28)
cor36_28 <- cor.test (Line36_28$Wing_area, Line36_28$Dev_time, method = c("pearson"))
cor36_28
#not significant
Line56_25 <- Cor[which(Cor$Line=="56" & Cor$Temp=="25"), ]
head (Line56_25)
cor56_25 <- cor.test (Line56_25$Wing_area, Line56_25$Dev_time, method = c("pearson"))
cor56_25
#significant
Line56_28 <- Cor[which(Cor$Line=="56" & Cor$Temp=="28"), ]
head (Line56_28)
cor56_28 <- cor.test (Line56_28$Wing_area, Line56_28$Dev_time, method = c("pearson"))
cor56_28
#significant
Line63_25 <- Cor[which(Cor$Line=="63" & Cor$Temp=="25"), ]
head (Line63_25)
cor63_25 <- cor.test (Line63_25$Wing_area, Line63_25$Dev_time, method = c("pearson"))
cor63_25
Line63_28 <- Cor[which(Cor$Line=="63" & Cor$Temp=="28"), ]
head (Line63_28)
cor63_28 <- cor.test (Line63_28$Wing_area, Line63_28$Dev_time, method = c("pearson"))
cor63_28
#significant
Line85_25 <- Cor[which(Cor$Line=="85" & Cor$Temp=="25"), ]
head (Line85_25)
cor85_25 <- cor.test (Line85_25$Wing_area, Line85_25$Dev_time, method = c("pearson"))
cor85_25
Line85_28 <- Cor[which(Cor$Line=="85" & Cor$Temp=="28"), ]
head (Line85_28)
cor85_28 <- cor.test (Line85_28$Wing_area, Line85_28$Dev_time, method = c("pearson"))
cor85_28
#almost significant
```
```{r}
#plotting overall correlations
plota <- ggscatter(Cor, x = "Dev_time", y = "Wing_area", colour = "PL", group = "PL",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Devtime", ylab = "Wingarea")
plota
pdf("./COR_wholedataset.pdf", useDingbats=FALSE)
grid.arrange(plota)
dev.off()
#plotting correlations by line
plotb <- ggscatter(Cor, x = "Dev_time", y = "Wing_area",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Devtime", ylab = "Wingarea") + facet_wrap (~Line)
plotb
pdf("./COR_subsetline2.pdf", useDingbats=FALSE)
grid.arrange(plotb)
dev.off()
#plotting correlations by line and temp
plotc <- ggscatter(Cor, x = "Dev_time", y = "Wing_area",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Devtime", ylab = "Wingarea") + facet_wrap (~Line + Temp)
plotc
pdf("./COR_subsetline&temp.pdf", useDingbats=FALSE)
grid.arrange(plotc)
dev.off()
```
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Cmd+Option+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Cmd+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.