forked from xingyaochen/turtleAnt_dataAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotting.Rmd
102 lines (81 loc) · 3.42 KB
/
plotting.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
---
title: "Periodic Checking of Turtle Ants"
author: "Xingyao Chen"
date: "7/20/2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(cache = TRUE)
```
#Install Relevant Libraries and Load the Data from GDrive
```{r}
setwd('../turtleAnt_dataAnalysis/')
library(ggplot2)
library(gsheet)
setwd('../turtleAnt_dataAnalysis/')
urlList=c('https://docs.google.com/spreadsheets/d/1cvECaZLMiSOCoJlqv3W8xpVNIWY5Nf5zsw8b7khrvSA/edit#gid=1236070938',
'https://docs.google.com/spreadsheets/d/1cvECaZLMiSOCoJlqv3W8xpVNIWY5Nf5zsw8b7khrvSA/edit#gid=943324237',
'https://docs.google.com/spreadsheets/d/1cvECaZLMiSOCoJlqv3W8xpVNIWY5Nf5zsw8b7khrvSA/edit#gid=1576199558',
'https://docs.google.com/spreadsheets/d/1cvECaZLMiSOCoJlqv3W8xpVNIWY5Nf5zsw8b7khrvSA/edit#gid=0',
'https://docs.google.com/spreadsheets/d/1cvECaZLMiSOCoJlqv3W8xpVNIWY5Nf5zsw8b7khrvSA/edit#gid=922087983',
'https://docs.google.com/spreadsheets/d/1cvECaZLMiSOCoJlqv3W8xpVNIWY5Nf5zsw8b7khrvSA/edit#gid=1728631886')
colData=data.frame()
colonies=c('T1','T2','T3','V1','V2','V3')
for(i in 1:length(urlList)){
coli=read.csv(text=gsheet2text(urlList[i], format='csv'))[,1:8]
coli$colony=colonies[i]
coli$Number.Workers=as.numeric(as.character(coli$Number.Workers))
print(names(coli))
colData=rbind(colData,coli)
}
```
#Clean Up Data and Add Time Info
```{r}
colData=colData[colData$Box!='O',]
#colDataSplit=split(colData, colData$colony)
dim(colData)
colData=na.omit(colData)
splitted=t(matrix(unlist(strsplit(as.character(colData$Date),'/')),nrow=3))
colData$Date=sprintf(paste(paste0('0',splitted[,1]),"%02d",paste0('20',splitted[,3]), sep='/'), as.numeric(splitted[,2]))
time=paste(colData$Date, colData$Time)
colData$Posix=as.POSIXct(time , format = "%m/%d/%Y %I:%M %p")
colData$PosixTime=as.POSIXct(colData$Time , format = "%I:%M %p")
colData$Number.Workers=as.numeric(as.character(colData$Number.Workers))
for(i in 1:nrow(colData)){
colData$Brood[i]=(colData$Number.Larva[i]!=0|colData$Number.Eggs[i]!=0)
}
summary(colData)
```
#Plot Number of Workers Over Time
```{r}
for(i in colonies){
#png(paste0('finalPoster/line_workers_col',i,'.png'))
p=ggplot(data=colData[colData$colony==i,], aes(x=Posix, y=Number.Workers, group=Box, color=Box, shape=Brood, size=Brood))+
geom_point()+
geom_line(size=1.3)+
scale_shape_manual(values=c(16, 18))+
scale_size_manual(values=c(1,4.5))+
labs(x='Time')+
scale_colour_manual(values=c( 'dodgerblue2','deepskyblue1','dodgerblue4', 'firebrick3', 'firebrick1', 'firebrick4'))+
theme_classic()+
theme(axis.title=element_text(size=13),axis.text=element_text(size=12, angle=45, hjust=1), legend.title=element_text(size=14),legend.text=element_text(size=12))
#geom_bar(stat='identity')
plot(p)
#graphics.off()
}
#
#
```
#Plot Summary of Final Count For Each Colony
```{r}
colData$DR=as.factor(t(matrix(unlist(strsplit(as.character(colData$Box), '')),nrow=2))[,1])
#png('finalPoster/final_counts.png')
ggplot(colData[colData$Time=='8:00 PM',], aes(y=Number.Workers, x=as.factor(colony), fill=DR))+
geom_bar(stat='identity', position='dodge')+
scale_fill_manual(values=c('dodgerblue2','firebrick'),name='Section')+
labs(x='Colony')+
theme_classic()+
theme(axis.title=element_text(size=13),axis.text=element_text(size=12, angle=45, hjust=1), legend.title=element_text(size=14),legend.text=element_text(size=12))
#graphics.off()
```