forked from xingyaochen/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 21.4 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
ggplot(fullSum,aes(y=value, x=Time, color=Section, group=Section))+
geom_line(size=1.3)+
geom_point()+
facet_wrap(~Colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13),
axis.text=element_text(size=12, angle=45, hjust=1),
legend.title=element_text(size=13),legend.text=element_text(size=12))+
labs(y='Ant Activity (# of entries and exits')+
theme_classic()
png('finalPoster/activity_ct.png')
ggplot(fullSum,aes(y=value, x=Time, color=Section, group=Section))+
geom_line(size=1.3)+
geom_point()+
facet_wrap(~Colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13),
axis.text=element_text(size=12, angle=45, hjust=1),
legend.title=element_text(size=13),legend.text=element_text(size=12))+
labs(y='Ant Activity (# of entries and exits')+
theme_classic()
graphics.off()
colData$DR=as.factor(t(matrix(unlist(strsplit(as.character(colData$Box), '')),nrow=2))[,1])
#d=read.csv('pixcount.csv')
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)
}
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")
summary(colData)
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)
}
install.packages('gridGraphics')
install.packages('png')
library(gridGraphics)
library(png)
system('mkdir finalPoster')
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()
}
#
#
# ggplot(data=colData, aes(x=Posix, y=Number.Workers, group=Box, color=Box))+
# geom_point()+
# geom_line()+
# scale_color_brewer(palette='RdBu')+
# facet_grid(colony~.)+
# theme_classic()
for(i in colonies){
png(paste0('7-12-17/bar_workers_col',i,'.png'))
p=ggplot(data=colData[colData$colony==i,], aes(x=Posix, y=Number.Workers, group=Box, fill=Box))+
geom_bar(stat='identity')+
scale_fill_manual(values=c( 'dodgerblue2','deepskyblue1','dodgerblue4', 'firebrick3', 'firebrick1', 'firebrick4'))+
theme_classic()+
labs(x='Time')+
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))
plot(p)
graphics.off()
}
head(colData)
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()
install.packages("gridGraphics")
install.packages("png")
install.packages("png")
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()
urls=c(
#'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=1849028624',
'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=0',
'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=433819656',
'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=1138436910')
colData=data.frame()
colonies=c(4,5,6)
for(i in 1:length(urls)){
coli=read.csv(text=gsheet2text(urls[i], format='csv'))[-1,1:14]
coli$colony=colonies[i]
print(names(coli))
colData=rbind(colData,coli)
}
summary(colData)
dim(colData)
colData=na.omit(colData)
colData$colony
#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(colData$Time , format = "%I:%M:%S")
colData$Enter.Box=as.numeric(as.character(colData$Enter.Box))
colData$Box=as.factor(colData$Box)
colData$colony=as.factor(colData$colony)
names(colData)
colData$Nest
colData=na.omit(colData)
head(colData)
system('mkdir 7-17-17')
for(i in colonies){
png(paste0('7-17-17/enterNest_col',i,'png'))
p=ggplot(colData[c(colData$colony==i&colData$Nest!=colData$Nest[1]),], aes(y=Enter.Nest, x=Posix, fill=Nest, color=Nest))+
#geom_bar(stat='identity')+
geom_line(size=1.5)+
labs(x='Time')+
scale_colour_manual(values=c( 'dodgerblue2','deepskyblue1','dodgerblue4', 'firebrick3', 'firebrick1', 'firebrick4'))+
theme(axis.title=element_text(size=14), legend.title=element_text(size=14),legend.text=element_text(size=12))+
theme_classic()
plot(p)
graphics.off()
}
BoxNest=as.factor(paste(colData$Box, colData$Nest))
for(i in colonies){
png(paste0('7-17-17/enterBox_col',i,'png'))
p=ggplot(colData[c(colData$colony==i),], aes(y=Enter.Box, x=Posix, fill=Box, color=Box))+
#geom_bar(stat='identity')+
scale_colour_manual(values=c('gray', 'gray','deepskyblue1','gray', 'dodgerblue2','dodgerblue4', 'gray', 'firebrick1','gray','firebrick3','gray', 'firebrick4'),
labels=c('1','2','3 (R2)','4','5 (R1)','6 (R3)','7','8 (D2)','9','10 (D1)','11','12 (D3)'))+
#scale_fill_manual(values=c('gray', 'gray','deepskyblue1','gray', 'dodgerblue2','dodgerblue4', 'gray', 'firebrick1','gray','firebrick3','gray', 'firebrick4'))+
geom_line(size=1.5)+
labs(x='Time')+
theme_classic()
plot(p)
graphics.off()
}
library(reshape2)
colData$Enter.Nest=as.numeric(as.character(colData$Enter.Nest))
colData$Exit.Nest=as.numeric(as.character(colData$Exit.Nest))
colData_s=colData[,c('Posix','Nest','Enter.Nest','Exit.Nest','colony')]
colData_s=colData_s[colData_s$Nest!=colData_s$Nest[1],]
colData_s$Enter.Nest=as.numeric(as.character(colData_s$Enter.Nest))
colData_s$Exit.Nest=as.numeric(as.character(colData_s$Exit.Nest))
colData_s$colony=as.factor(colData_s$colony)
sumdf=cbind(melt(acast(colData_s[,c(2,5,3)], Nest~colony, sum)),
melt(acast(colData_s[,c(2,5,4)], Nest~colony, sum))$value)
names(sumdf)=c('Nest','Colony','Enter','Exit')
sumdf=melt(sumdf, id.vars=c('Nest','Colony'))
png('finalPoster//leaveNestBar.png')
ggplot(sumdf, aes(x=Nest, y=value,fill=variable, group=variable))+
geom_bar(stat='identity', position='dodge')+
scale_fill_manual(values=c('black','grey'))+
facet_wrap(~Colony)+
labs(y='# of Ants')+
theme_classic()
graphics.off()
###
r=c(2,3,5,6)
d=c(7,8,9,10,11,12)
for(i in 1:nrow(colData)){
if(colData$Box[i]%in%r){
colData$Section[i]='R'
}
else if(colData$Box[i]%in%d){
colData$Section[i]='D'
}
}
colData_sec=colData[!is.na(colData$Section),]
colData_s=colData_sec[,c('Posix','Section','Enter.Box','Exit.Box','colony')]
#colData_s=colData_s[colData_s$Box!=colData_s$Box[1],]
colData_s$Enter.Box=as.numeric(as.character(colData_s$Enter.Box))
colData_s$Exit.Box=as.numeric(as.character(colData_s$Exit.Box))
colData_s$colony=as.factor(colData_s$colony)
sumdf=cbind(melt(acast(colData_s[,c(2,5,3)], Section~colony, sum)),
melt(acast(colData_s[,c(2,5,4)], Section~colony, sum))$value)
names(sumdf)=c('Section','Colony','Enter','Exit')
sumdf=melt(sumdf, id.vars=c('Section','Colony'))
png('finalPoster/leaveBoxBar.png')
ggplot(sumdf, aes(x=Section, y=value,fill=Section, group=variable, alpha=variable))+
geom_bar(stat='identity', position='dodge')+
scale_alpha_discrete(range = c(0.7, 1))+
scale_fill_manual(values=c('dodgerblue2','firebrick'),name=c('Section','Activity'))+
facet_wrap(~Colony)+
labs(y='Ant Activity',x='Box #')+
theme_classic()+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13), legend.title=element_text(size=13),legend.text=element_text(size=12))+
graphics.off()
colData_s=colData_sec[,c('Posix','Section','Enter.Box','Exit.Box','colony')]
#colData_s=colData_s[colData_s$Box!=colData_s$Box[1],]
colData_s$Enter.Box=as.numeric(as.character(colData_s$Enter.Box))
colData_s$Exit.Box=as.numeric(as.character(colData_s$Exit.Box))
colData_s$colony=as.factor(colData_s$colony)
colData_split=split(colData_s, colData_s$colony)
cols=c(4,5,6)
fullSum=data.frame()
for(i in 1:length(colData_split)){
sumdf=cbind(melt(acast(colData_split[[i]][,c(1,2,3)], Section~Posix, sum)),
melt(acast(colData_split[[i]][,c(1,2,4)], Section~Posix, sum))$value)
sumdf$Colony=cols[i]
names(sumdf)=c('Section','Time','Exit','Enter','Colony')
fullSum=rbind(fullSum,sumdf)
}
fullSum=melt(fullSum, id.vars=c('Section','Colony','Time'))
head(fullSum)
fullSum$Time=as.POSIXct(fullSum$Time)
png('finalPoster/activity_ct.png')
ggplot(fullSum,aes(y=value, x=Time, color=Section, group=Section))+
geom_line(size=1.3)+
geom_point()+
facet_wrap(~Colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13),
axis.text=element_text(size=12, angle=45, hjust=1),
legend.title=element_text(size=13),legend.text=element_text(size=12))+
labs(y='Ant Activity (# of entries and exits')+
theme_classic()
graphics.off()
##
colData=data.frame()
colonies=c(4,5,6)
for(i in 1:length(urls)){
coli=read.csv(text=gsheet2text(urls[i], format='csv'))[-1,c(2,5,16:17)]
coli$colony=colonies[i]
print(names(coli))
colData=rbind(colData,coli)
}
summary(colData)
dim(colData)
colDataOR=na.omit(colData[,-3])
colDataOD=na.omit(colData[,-4])
colData$Posix=as.POSIXct(colData$Time , format = "%I:%M:%S")
#colData$Enter.Box=as.numeric(as.character(colData$Enter.Box))
#colData$Box=as.factor(colData$Box)
colData$colony=as.factor(colData$colony)
dts=na.omit(melt(colData[,-c(1:2)], id.vars=c("Posix",'colony')))
head(dts)
ggplot(dts, aes(x=Posix,y=value, color=as.factor(variable)))+
geom_point()+
geom_line()+
facet_wrap(~colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13), legend.title=element_text(size=13),legend.text=element_text(size=12))+
theme_classic()
png('finalPoster/activity_ct.png')
ggplot(fullSum,aes(y=value, x=Time, color=Section, group=Section))+
geom_line(size=1.3)+
geom_point()+
facet_wrap(~Colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13),
axis.text=element_text(size=12, angle=45, hjust=1),
legend.title=element_text(size=13),legend.text=element_text(size=12))+
labs(y='Ant Activity (# of entries and exits')+
theme_classic()
graphics.off()
urls=c(
#'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=1849028624',
'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=0',
'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=433819656',
'https://docs.google.com/spreadsheets/d/1OCKoUgQ_A-do18Uc_ulIzoQ_P22nb8lim9wBlwROR4c/edit#gid=1138436910')
colData=data.frame()
colonies=c('V1','V2','V3')
for(i in 1:length(urls)){
coli=read.csv(text=gsheet2text(urls[i], format='csv'))[-1,1:14]
coli$colony=colonies[i]
print(names(coli))
colData=rbind(colData,coli)
}
summary(colData)
dim(colData)
colData=na.omit(colData)
colData$colony
#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(colData$Time , format = "%I:%M:%S")
colData$Enter.Box=as.numeric(as.character(colData$Enter.Box))
colData$Box=as.factor(colData$Box)
colData$colony=as.factor(colData$colony)
names(colData)
colData$Nest
colData=na.omit(colData)
head(colData)
system('mkdir 7-17-17')
for(i in colonies){
png(paste0('7-17-17/enterNest_col',i,'png'))
p=ggplot(colData[c(colData$colony==i&colData$Nest!=colData$Nest[1]),], aes(y=Enter.Nest, x=Posix, fill=Nest, color=Nest))+
#geom_bar(stat='identity')+
geom_line(size=1.5)+
labs(x='Time')+
scale_colour_manual(values=c( 'dodgerblue2','deepskyblue1','dodgerblue4', 'firebrick3', 'firebrick1', 'firebrick4'))+
theme(axis.title=element_text(size=14), legend.title=element_text(size=14),legend.text=element_text(size=12))+
theme_classic()
plot(p)
graphics.off()
}
BoxNest=as.factor(paste(colData$Box, colData$Nest))
for(i in colonies){
png(paste0('7-17-17/enterBox_col',i,'png'))
p=ggplot(colData[c(colData$colony==i),], aes(y=Enter.Box, x=Posix, fill=Box, color=Box))+
#geom_bar(stat='identity')+
scale_colour_manual(values=c('gray', 'gray','deepskyblue1','gray', 'dodgerblue2','dodgerblue4', 'gray', 'firebrick1','gray','firebrick3','gray', 'firebrick4'),
labels=c('1','2','3 (R2)','4','5 (R1)','6 (R3)','7','8 (D2)','9','10 (D1)','11','12 (D3)'))+
#scale_fill_manual(values=c('gray', 'gray','deepskyblue1','gray', 'dodgerblue2','dodgerblue4', 'gray', 'firebrick1','gray','firebrick3','gray', 'firebrick4'))+
geom_line(size=1.5)+
labs(x='Time')+
theme_classic()
plot(p)
graphics.off()
}
library(reshape2)
colData$Enter.Nest=as.numeric(as.character(colData$Enter.Nest))
colData$Exit.Nest=as.numeric(as.character(colData$Exit.Nest))
colData_s=colData[,c('Posix','Nest','Enter.Nest','Exit.Nest','colony')]
colData_s=colData_s[colData_s$Nest!=colData_s$Nest[1],]
colData_s$Enter.Nest=as.numeric(as.character(colData_s$Enter.Nest))
colData_s$Exit.Nest=as.numeric(as.character(colData_s$Exit.Nest))
colData_s$colony=as.factor(colData_s$colony)
sumdf=cbind(melt(acast(colData_s[,c(2,5,3)], Nest~colony, sum)),
melt(acast(colData_s[,c(2,5,4)], Nest~colony, sum))$value)
names(sumdf)=c('Nest','Colony','Enter','Exit')
sumdf=melt(sumdf, id.vars=c('Nest','Colony'))
png('finalPoster//leaveNestBar.png')
ggplot(sumdf, aes(x=Nest, y=value,fill=variable, group=variable))+
geom_bar(stat='identity', position='dodge')+
scale_fill_manual(values=c('black','grey'))+
facet_wrap(~Colony)+
labs(y='# of Ants')+
theme_classic()
graphics.off()
###
r=c(2,3,5,6)
d=c(7,8,9,10,11,12)
for(i in 1:nrow(colData)){
if(colData$Box[i]%in%r){
colData$Section[i]='R'
}
else if(colData$Box[i]%in%d){
colData$Section[i]='D'
}
}
colData_sec=colData[!is.na(colData$Section),]
colData_s=colData_sec[,c('Posix','Section','Enter.Box','Exit.Box','colony')]
#colData_s=colData_s[colData_s$Box!=colData_s$Box[1],]
colData_s$Enter.Box=as.numeric(as.character(colData_s$Enter.Box))
colData_s$Exit.Box=as.numeric(as.character(colData_s$Exit.Box))
colData_s$colony=as.factor(colData_s$colony)
sumdf=cbind(melt(acast(colData_s[,c(2,5,3)], Section~colony, sum)),
melt(acast(colData_s[,c(2,5,4)], Section~colony, sum))$value)
names(sumdf)=c('Section','Colony','Enter','Exit')
sumdf=melt(sumdf, id.vars=c('Section','Colony'))
png('finalPoster/leaveBoxBar.png')
ggplot(sumdf, aes(x=Section, y=value,fill=Section, group=variable, alpha=variable))+
geom_bar(stat='identity', position='dodge')+
scale_alpha_discrete(range = c(0.7, 1))+
scale_fill_manual(values=c('dodgerblue2','firebrick'),name=c('Section','Activity'))+
facet_wrap(~Colony)+
labs(y='Ant Activity',x='Box #')+
theme_classic()+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13), legend.title=element_text(size=13),legend.text=element_text(size=12))+
graphics.off()
colData_s=colData_sec[,c('Posix','Section','Enter.Box','Exit.Box','colony')]
#colData_s=colData_s[colData_s$Box!=colData_s$Box[1],]
colData_s$Enter.Box=as.numeric(as.character(colData_s$Enter.Box))
colData_s$Exit.Box=as.numeric(as.character(colData_s$Exit.Box))
colData_s$colony=as.factor(colData_s$colony)
colData_split=split(colData_s, colData_s$colony)
cols=c('V1','V2','V3')
fullSum=data.frame()
for(i in 1:length(colData_split)){
sumdf=cbind(melt(acast(colData_split[[i]][,c(1,2,3)], Section~Posix, sum)),
melt(acast(colData_split[[i]][,c(1,2,4)], Section~Posix, sum))$value)
sumdf$Colony=cols[i]
names(sumdf)=c('Section','Time','Exit','Enter','Colony')
fullSum=rbind(fullSum,sumdf)
}
fullSum=melt(fullSum, id.vars=c('Section','Colony','Time'))
head(fullSum)
fullSum$Time=as.POSIXct(fullSum$Time)
png('finalPoster/activity_ct.png')
ggplot(fullSum,aes(y=value, x=Time, color=Section, group=Section))+
geom_line(size=1.3)+
geom_point()+
facet_wrap(~Colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13),
axis.text=element_text(size=12, angle=45, hjust=1),
legend.title=element_text(size=13),legend.text=element_text(size=12))+
labs(y='Ant Activity (# of entries and exits')+
theme_classic()
graphics.off()
##
colData=data.frame()
colonies=c(4,5,6)
for(i in 1:length(urls)){
coli=read.csv(text=gsheet2text(urls[i], format='csv'))[-1,c(2,5,16:17)]
coli$colony=colonies[i]
print(names(coli))
colData=rbind(colData,coli)
}
summary(colData)
dim(colData)
colDataOR=na.omit(colData[,-3])
colDataOD=na.omit(colData[,-4])
colData$Posix=as.POSIXct(colData$Time , format = "%I:%M:%S")
#colData$Enter.Box=as.numeric(as.character(colData$Enter.Box))
#colData$Box=as.factor(colData$Box)
colData$colony=as.factor(colData$colony)
dts=na.omit(melt(colData[,-c(1:2)], id.vars=c("Posix",'colony')))
head(dts)
ggplot(dts, aes(x=Posix,y=value, color=as.factor(variable)))+
geom_point()+
geom_line()+
facet_wrap(~colony)+
scale_color_manual(values=c('dodgerblue2','firebrick'),name=c('Section'))+
theme(title=element_text(size=14, face='bold'),axis.title=element_text(size=13), legend.title=element_text(size=13),legend.text=element_text(size=12))+
theme_classic()
logData=read.csv('pollinator_visitation_fullData_logTrans.csv')
head(logData)
setwd('../bee')
logData=read.csv('pollinator_visitation_fullData_logTrans.csv')
head(logData)
logData_split=split(logData, logData$Date)
i=1
sum(logData_split[[i]]$Visits)
sum(logData_split[[i]]$Visits&logData_split[[i]]$Size=='Large')
for(i in 1:length(logData_split)){
add=data.frame(Date=names(logData_split)[i],LargeVisit=sum(logData_split[[i]]$Visits&logData_split[[i]]$Size=='Large'), SmallVisit=sum(logData_split[[i]]$Visits&logData_split[[i]]$Size=='Small'))
ttest=rbind(ttest, add)
}
head(logData)
logData_split=split(logData, logData$Date)
ttest=data.frame()
for(i in 1:length(logData_split)){
add=data.frame(Date=names(logData_split)[i],LargeVisit=sum(logData_split[[i]]$Visits&logData_split[[i]]$Size=='Large'), SmallVisit=sum(logData_split[[i]]$Visits&logData_split[[i]]$Size=='Small'))
ttest=rbind(ttest, add)
}
ttest
t.test(ttest$LargeVisit, ttest$SmallVisit)
ttest
t.test(ttest$LargeVisit, ttest$SmallVisit)
?t.test
t.test(ttest$LargeVisit, ttest$SmallVisit, alternative='greater')
ttest
4.714286/(4.714286+1.285714)
mylogit <- lmer(Honeybees ~
height+
Avg.open.flowers.per.inflorescence+
Total.inflorescenses+
Sugar_content+
(1|Date), data=logData)
an=Anova(mylogit)
an
summary(logData)
melt(ttest)
tmelt=melt(ttest)
tmelt
ggplot(tmelt, aes(x=Date, y=value, fill=variable))+geom_bar()
ggplot(tmelt, aes(x=Date, y=value, fill=variable))+geom_bar(stat='identity')
ggplot(tmelt, aes(x=Date, y=value, fill=variable))+geom_bar(stat='identity', position='dodge')
?sjp.lmer
sjp.lmer(mylogit, type = "pred", facet.grid = FALSE,
vars = c(vars[i],'Date'), plot=F, show.p=T,show.ci=T)
vars[i]
sjp.lmer(mylogit, type = "pred", facet.grid = FALSE,
vars = c(vars[1],'Date'), plot=F, show.p=T,show.ci=T)
mylogit <- lmer(Honeybees ~
Avg.open.flowers.per.inflorescence+
Total.inflorescenses+
Sugar_content+
height+
(1|Date), data=logData)
an=Anova(mylogit)
an
pvals=round(an$`Pr(>Chisq)`,4)
pvals