forked from xingyaochen/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_poster_figs.Rmd
113 lines (96 loc) · 3.04 KB
/
final_poster_figs.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
title: "Final Poster Figures"
author: "Xingyao Chen"
date: "7/19/2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(cache = TRUE)
```
Install Necessary Pakcages and Load Data
```{r cars}
#install_github("ggbiplot", "vqv")
#library(ggbiplot)
library(lme4)
#install.packages('dplyr')
library(dplyr)
library(devtools)
#devtools::install_github("strengejacke/sjPlot",force = TRUE)
library(sjPlot)
library(sjmisc)
library(reshape2)
library(ggplot2)
library(car)
setwd('../bee')
logData=read.csv('pollinator_visitation_fullData_logTrans.csv')
```
Test Significant of the Difference Between Honeybees Visiting Small vs Large Plants
```{r}
data_dt=split(logData, logData$Date)
#Make a dataframe, summing visits for small and large plants
ttest=data.frame()
for(i in 1:length(data_dt)){
add=data.frame(Date=names(data_dt)[i],LargeVisit=sum(data_dt[[i]]$Visits&data_dt[[i]]$Size=='Large'), SmallVisit=sum(data_dt[[i]]$Visits&data_dt[[i]]$Size=='Small'))
ttest=rbind(ttest, add)
}
#peek
ttest
```
#Plot and perform one-tailed t test
```{r, warnings=F}
t.test(ttest$LargeVisit, ttest$SmallVisit, alternative='greater')
tmelt=melt(ttest)
ggplot(tmelt, aes(x=Date, y=value, fill=variable))+geom_bar(stat='identity', position='dodge')+theme_classic()
```
#Make Scatter Plots of Honeybees vs Date, Separated by Large and Small Plants
```{r, warnings=F}
theshold=c()
wholedf=data.frame()
for( i in 1:length(data_dt)){
theshold[i]=median(data_dt[[i]]$Honeybees)
data_dt[[i]]$Median=theshold[i]
wholedf=rbind(wholedf, data_dt[[i]])
}
logData=wholedf
ggplot(data=logData, aes(x='', y=Honeybees, color=Size))+
geom_jitter(width = 0.15)+
facet_grid(~Date)+
geom_hline(aes(yintercept = Median),lty=5, size=0.8)+
labs(x="Days", size=4)+
theme_classic()+
theme(axis.title=element_text(size=14), legend.title=element_text(size=14),legend.text=element_text(size=12))
```
#Linear Modeling with Mixed Effects
```{r}
mylogit <- lmer(Honeybees ~
Avg.open.flowers.per.inflorescence+
Total.inflorescenses+
Sugar_content+
height+
(1|Date), data=logData)
summary(mylogit)
an=Anova(mylogit)
pvals=round(an$`Pr(>Chisq)`,4)
```
#Plot Results
```{r}
sjp.setTheme()
vars=c('Avg.open.flowers.per.inflorescence','Total.inflorescenses','Sugar_content',
'height')
tit=c('Reward+Efficiency','Poential Reward for Colony', 'Reward per Inflorescense','Salience')
for(i in 1:length(vars)){
ploot2=sjp.lmer(mylogit, type = "pred", facet.grid = FALSE,
vars = c(vars[i],'Date'), prnt.plot=F,show.ci=T)
ploot2=ploot2[[2]]+
labs(x=vars[i])+
ggtitle(tit[i], subtitle=paste0("(p-val = ",pvals[i],')'))+
theme_classic()+
scale_color_brewer(palette = 'Paired')+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=14), legend.title=element_text(size=14),legend.text=element_text(size=12))
#pdf(paste0('forPoster/lmerFull_diffSlope2_',vars[i],'.pdf'))
plot(ploot2)
#dev.off()
#graphics.off()
}
```