-
Notifications
You must be signed in to change notification settings - Fork 0
/
SFZFunctions.R
6119 lines (5976 loc) · 751 KB
/
SFZFunctions.R
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
####################################################################################################################
## Author: GREG CHISM
## Date: APR 2022
## email: [email protected]
## Project: Nest shape influences colony organization in ants: spatial distribution and connectedness of colony members differs from that predicted by random movement and is affected by available space
## Title: Site fidelity zone assignment, calculations, and distance functions
####################################################################################################################
# This code is to replicate the analyses and figures for the following:
# Zone assignment for site fidelity
# Fidelity zone calculations
# Fidelity zone distance functions (to nest entrance and brood center)
####################################################################################################################
# IMPORT ALL NECESSARY DATASETS
# This code imports all necessary data sets for the script below
####################################################################################################################
# COLOR REFRENCE DATA SET
ColorRefFull <- read.csv("ColorRefFull.csv")
# NEST AREA REFERENCES
NestAreaFull <- read.csv("NestAreaFull.csv")
# SCALING REFERENCE DATA SET FOR CIRCLE NESTS (BASICALLY COLONY SIZE)
ScalingCircleSFZ <- read.csv("ScalingCircleSFZ.csv")
####################################################################################################################
# CORRECTING COLOR COORDINATES
# The following function corrects viable worker color identification
# This means that there is a missing color and only one possible combination
# The function uses the worker color combinations for each colony as a reference
# First the worker data set is set so that missing colors are "X"
# Then the colors are filled by looking at all possible combinations of one missing color mark for each colony
# The function then checks for any rows that didn't have a corrected combination, resulting most likely from the color being misinterpreted
####################################################################################################################
ColorCoords <- function(data.table){
# Fixing missing marks to only by "X"
ColorSetting <- data.table %>%
# Separate the AntID column into 4 columns, one for each mark
separate(AntID, c("Head", "Thorax", "Abd1", "Abd2"), sep = ",", remove = FALSE) %>%
# Changing "?" values to "X" in each column
mutate(Head = ifelse(Head == "?", "X", Head),
Thorax = ifelse(Thorax == "?", "X", Thorax),
Abd1 = ifelse(Abd1 == "?", "X", Abd1),
Abd2 = ifelse(Abd2 == "?", "X", Abd2)) %>%
# Uniting the 4 columns to the original AntID column
unite(AntID, c("Head", "Thorax", "Abd1", "Abd2"), sep = ",", remove = TRUE)
# Creating a reference data set of all possible combinations for one missing color mark
ColorRefFull <- ColorRefFull%>%
# Unite the color reference columns
unite(AntIDRef, c("Head", "Thorax", "Abd1", "Abd2"), sep = ",", remove = FALSE)
# Creating individual data sets to create one column full of "X"
X1 <- ColorRefFull
X2 <- ColorRefFull
X3 <- ColorRefFull
X4 <- ColorRefFull
# Filling one of the reference columns
X1[3] <- "X"
X2[4] <- "X"
X3[5] <- "X"
X4[6] <- "X"
# Joining the reference data sets
FullColorCoordRef <- full_join(X1, X2) %>%
full_join(X3) %>%
full_join(X4) %>%
# Uniting the reference columns
# This new column is the same name as in the real data set
# So any column with the same missing value will now have the true color combination in the AntIDRef column
unite(AntID, c("Head", "Thorax", "Abd1", "Abd2"), sep = ",", remove = TRUE)
# Creating the final data set with the original combination and true color combination
SFZDataFull <<- left_join(ColorSetting, FullColorCoordRef) %>%
# Separating the true AntID column and removing rows with more than one "X"
# This is done by creating a column that assigns a 1 when two columns are "X"
separate(AntID, c("Head", "Thorax", "Abd1", "Abd2"), sep = ",", remove = FALSE) %>%
mutate(XCount = ifelse(Head == "X" & Thorax == "X" |
Abd1 == "X" & Abd2 == "X" |
Head == "X" & Abd1 == "X" |
Head == "X" & Abd2 == "X" |
Thorax == "X" & Abd1 == "X"|
Thorax == "X" & Abd2 == "X", 1, 0),
# Changing NA values in AntIDRef to 0, which occurs when a AntID doesn't have just one missing color
# The objective is to remove both rows with more than two missing colors and keep all fully marked workers
AntIDRef = ifelse(is.na(AntIDRef), 0, AntIDRef),
AntID = ifelse(AntIDRef == "0", AntID, AntIDRef)) %>%
# Filtering out rows with more than one "X", or missing color
filter(XCount != 1) %>%
# Selecting the desired columns
select(Colony, Nest, Day, ScaledX, ScaledY, Bin, AntID) %>%
distinct()
}
# Run color correction function on the combined workers data set
ColorCoords(FullDataCoordWorkersRD1_RD2)
####################################################################################################################
# SITE FIDELITY ASSIGNMENT FUNCTION
# The code below bins x and y coordinate colony data into twenty-four even area nest sections
# Note that the code is specifically used below for the low density treatment colonies (11-20)
# This is because the high density treatment colonies (1-10) were done through excel but can be run through this script as well
# To do this, a reference data set of bin coordinates is used and coordinates are run through a series of conditional statements
# Where each conditional statement checks whether the coordinate is in one of twenty-four bins sequentially
# The reference data set for tube nest bins was used here as well, since the bins were divided by three to achieve the desired nest sections here
# The circle nest shape has a different set of reference coordinates
####################################################################################################################
# Creating the reference zones for the circle nest shape
BinCoord24Circ <- NestAreaFull %>%
mutate(Radius = Diameter / 2) %>% # Radius of each circle
left_join(ScalingCircleSFZ) %>% # Joining the scaling reference data set
mutate(AddValue = Radius * Scaling) %>% # Value to add to the center of the circle nest for zones, where instead of manually assigning reference coordinates for every bin, a value is added from the nest center (3.75) to find it instead
distinct() # Remove duplicates
# COLONY 1
CoordBinnedSFZ <- function(data_table){
# Filtering the desired colony from the reference data sets
SFZBinCoordAssign <- BinCoordFull %>%
filter(Colony == "1")
BinCoordAssign <- BinCoordFull %>%
filter(Colony == "1")
BinCoord24Circ <- BinCoord24Circ %>%
filter(Colony == "1")
# Filtering the desired colony from the worker tube nest data sets
# Note that the site fidelity Bins will be referred to as "Zones" from here on
# TUBE NEST ZONES
Colony1BinnedTubeSFZ <- data_table %>%
filter(Colony == "1" & Nest == "Tube") %>%
# The following columns create reference points from the eight even area bin reference data set
# The goal is to produce a segment length that is along one of the eight bins, each encompassing three of the twenty-four zones
# Since these bins were cut into thirds, it is more accurate to simply use these segments than to create a whole new set of reference coordinates
mutate(Bin1.3 = SFZBinCoordAssign$ScaledY[2], #Length from Zone 1 to 3
Bin4.6 = abs(SFZBinCoordAssign$ScaledX[2] - SFZBinCoordAssign$ScaledX[3]), #Length from Zone 4 to 6
Bin7.9 = abs(SFZBinCoordAssign$ScaledY[4] - SFZBinCoordAssign$ScaledY[3]), #Length from Zone 7 to 9
Bin10.12 = abs(SFZBinCoordAssign$ScaledX[5] - SFZBinCoordAssign$ScaledX[4]), #Length from Zone 10 to 12
Bin13.15 = abs(SFZBinCoordAssign$ScaledX[6] - SFZBinCoordAssign$ScaledX[5]), #Length from Zone 13 to 15
Bin16.18 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[6]), #Length from Zone 16 to 18
Bin19.21 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 19 to 21
Bin22.24 = abs(SFZBinCoordAssign$ScaledX[8] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 22 to 24
# Binning the worker coordinates into a Zone
Zone =
# Zone 1
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY <= (1/3) * (Bin1.3), 1,
# Zone 2
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (1/3) * (Bin1.3) &
ScaledY <= (2/3) * (Bin1.3), 2,
# Zone 3
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (2/3) * (Bin1.3) &
ScaledY <= (Bin1.3), 3,
# Zone 4
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + (Bin4.6) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 4,
# Zone 5
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 5,
# Zone 6
if_else(ScaledX <= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX >= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 6,
# Zone 7
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY <= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)), 7,
# Zone 8
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)), 8,
# Zone 9
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + (Bin7.9), 9,
# Zone 10
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 10,
# Zone 11
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledX <= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 11,
# Zone 12
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX >= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 12,
# Zone13
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX <= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 13,
# Zone 14
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 14,
# Zone 15
if_else( ScaledX >= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 15,
# Zone 16
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledX <= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 16,
# Zone 17
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 17,
# Zone 18
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + Bin16.18 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 18,
# Zone 19
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] &
ScaledY >= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21), 19,
# Zone 20
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21) &
ScaledY >= BinCoordAssign$ScaledY[7] - (2/3) * (Bin19.21), 20,
# Zone 21
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] - (2/3) * (Bin19.21) &
ScaledY >= BinCoordAssign$ScaledY[7] - (Bin19.21), 21,
# Zone 22
if_else(ScaledX >= BinCoordAssign$ScaledX[9] + ((2/3) * (Bin22.24)) &
ScaledX <= BinCoordAssign$ScaledX[9] + (Bin22.24) &
ScaledY <= BinCoordAssign$ScaledY[9], 22,
# Zone 23
if_else(ScaledX <= BinCoordAssign$ScaledX[9] + ((2/3) * (Bin22.24)) &
ScaledX >= BinCoordAssign$ScaledX[9] + ((1/3) * (Bin22.24)) &
ScaledY <= BinCoordAssign$ScaledY[9], 23,
# Zone 24
if_else(ScaledX >= BinCoordAssign$ScaledX[9] &
ScaledX <= BinCoordAssign$ScaledX[9] + (1/3) * (Bin22.24) &
ScaledY <= BinCoordAssign$ScaledY[9], 24, 0
)))))))))))))))))))))))))
# CIRCLE NEST ZONES
Colony1BinnedCircleSFZ <- data_table %>%
filter(Colony == "1" & Nest == "Circle") %>%
mutate(Zone =
# Zone 1
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 1,
# Zone 2
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 2,
# Zone 3
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 3,
# Zone 4
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 4,
# Zone 5
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 5,
# Zone 6
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 6,
# Zone 7
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 7,
# Zone 8
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 8,
# Zone 9
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 9,
# Zone 10
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 10,
# Zone 11
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 11,
# Zone 12
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 12,
# Zone 13
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 13,
# Zone 14
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 14,
# Zone 15
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 15,
# Zone 16
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 16,
# Zone 17
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 17,
# Zone 18
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 18,
# Zone 19
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 19,
# Zone 20
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 20,
# Zone 21
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 21,
# Zone 22
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 22,
# Zone 23
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 23,
# Zone 24
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 24, 0
)))))))))))))))))))))))))
# Join the site fidelity zone data sets
Colony1BinnedSFZ <<- full_join(Colony1BinnedTubeSFZ, Colony1BinnedCircleSFZ) %>%
select(Colony, Nest, Day, Bin, ScaledX, ScaledY, Zone, AntID)
}
# Run the zone assignment function on the usable color coordinates worker data set
CoordBinnedSFZ(SFZDataFull)
# COLONY 2
CoordBinnedSFZ <- function(data_table){
# Filtering the desired colony from the reference data sets
SFZBinCoordAssign <- BinCoordFull %>%
filter(Colony == "2")
BinCoordAssign <- BinCoordFull %>%
filter(Colony == "2")
BinCoord24Circ <- BinCoord24Circ %>%
filter(Colony == "2")
# Filtering the desired colony from the worker tube nest data sets
# Note that the site fidelity Bins will be referred to as "Zones" from here on
# TUBE NEST ZONES
Colony2BinnedTubeSFZ <- data_table %>%
filter(Colony == "2" & Nest == "Tube") %>%
# The following columns create reference points from the eight even area bin reference data set
# The goal is to produce a segment length that is along one of the eight bins, each encompassing three of the twenty-four zones
# Since these bins were cut into thirds, it is more accurate to simply use these segments than to create a whole new set of reference coordinates
mutate(Bin1.3 = SFZBinCoordAssign$ScaledY[2], #Length from Zone 1 to 3
Bin4.6 = abs(SFZBinCoordAssign$ScaledX[2] - SFZBinCoordAssign$ScaledX[3]), #Length from Zone 4 to 6
Bin7.9 = abs(SFZBinCoordAssign$ScaledY[4] - SFZBinCoordAssign$ScaledY[3]), #Length from Zone 7 to 9
Bin10.12 = abs(SFZBinCoordAssign$ScaledX[5] - SFZBinCoordAssign$ScaledX[4]), #Length from Zone 10 to 12
Bin13.15 = abs(SFZBinCoordAssign$ScaledX[6] - SFZBinCoordAssign$ScaledX[5]), #Length from Zone 13 to 15
Bin16.18 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[6]), #Length from Zone 16 to 18
Bin19.21 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 19 to 21
Bin22.24 = abs(SFZBinCoordAssign$ScaledX[8] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 22 to 24
# Binning the worker coordinates into a Zone
Zone =
# Zone 1
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY <= (1/3) * (Bin1.3), 1,
# Zone 2
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (1/3) * (Bin1.3) &
ScaledY <= (2/3) * (Bin1.3), 2,
# Zone 3
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (2/3) * (Bin1.3) &
ScaledY <= (Bin1.3), 3,
# Zone 4
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + (Bin4.6) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 4,
# Zone 5
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 5,
# Zone 6
if_else(ScaledX <= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX >= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 6,
# Zone 7
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY <= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)), 7,
# Zone 8
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)), 8,
# Zone 9
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + (Bin7.9), 9,
# Zone 10
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 10,
# Zone 11
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledX <= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 11,
# Zone 12
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX >= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 12,
# Zone13
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX <= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 13,
# Zone 14
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 14,
# Zone 15
if_else( ScaledX >= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 15,
# Zone 16
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledX <= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 16,
# Zone 17
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 17,
# Zone 18
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + Bin16.18 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 18,
# Zone 19
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] &
ScaledY >= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21), 19,
# Zone 20
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21) &
ScaledY >= BinCoordAssign$ScaledY[7] - (2/3) * (Bin19.21), 20,
# Zone 21
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] - (2/3) * (Bin19.21) &
ScaledY >= BinCoordAssign$ScaledY[7] - (Bin19.21), 21,
# Zone 22
if_else(ScaledX >= BinCoordAssign$ScaledX[9] + ((2/3) * (Bin22.24)) &
ScaledX <= BinCoordAssign$ScaledX[9] + (Bin22.24) &
ScaledY <= BinCoordAssign$ScaledY[9], 22,
# Zone 23
if_else(ScaledX <= BinCoordAssign$ScaledX[9] + ((2/3) * (Bin22.24)) &
ScaledX >= BinCoordAssign$ScaledX[9] + ((1/3) * (Bin22.24)) &
ScaledY <= BinCoordAssign$ScaledY[9], 23,
# Zone 24
if_else(ScaledX >= BinCoordAssign$ScaledX[9] &
ScaledX <= BinCoordAssign$ScaledX[9] + (1/3) * (Bin22.24) &
ScaledY <= BinCoordAssign$ScaledY[9], 24, 0
)))))))))))))))))))))))))
# CIRCLE NEST ZONES
Colony2BinnedCircleSFZ <- data_table %>%
filter(Colony == "2" & Nest == "Circle") %>%
mutate(Zone =
# Zone 1
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 1,
# Zone 2
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 2,
# Zone 3
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 3,
# Zone 4
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 4,
# Zone 5
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 5,
# Zone 6
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 6,
# Zone 7
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 7,
# Zone 8
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 8,
# Zone 9
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 9,
# Zone 10
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 10,
# Zone 11
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 11,
# Zone 12
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 12,
# Zone 13
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 13,
# Zone 14
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 14,
# Zone 15
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 15,
# Zone 16
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 16,
# Zone 17
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 17,
# Zone 18
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 18,
# Zone 19
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 19,
# Zone 20
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 20,
# Zone 21
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 21,
# Zone 22
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 22,
# Zone 23
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 23,
# Zone 24
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 24, 0
)))))))))))))))))))))))))
# Join the site fidelity zone data sets
Colony2BinnedSFZ <<- full_join(Colony2BinnedTubeSFZ, Colony2BinnedCircleSFZ) %>%
select(Colony, Nest, Day, Bin, ScaledX, ScaledY, Zone, AntID)
}
# Run the zone assignment function on the usable color coordinates worker data set
CoordBinnedSFZ(SFZDataFull)
# COLONY 3
CoordBinnedSFZ <- function(data_table){
# Filtering the desired colony from the reference data sets
SFZBinCoordAssign <- BinCoordFull %>%
filter(Colony == "3")
BinCoordAssign <- BinCoordFull %>%
filter(Colony == "3")
BinCoord24Circ <- BinCoord24Circ %>%
filter(Colony == "3")
# Filtering the desired colony from the worker tube nest data sets
# Note that the site fidelity Bins will be referred to as "Zones" from here on
# TUBE NEST ZONES
Colony3BinnedTubeSFZ <- data_table %>%
filter(Colony == "3" & Nest == "Tube") %>%
# The following columns create reference points from the eight even area bin reference data set
# The goal is to produce a segment length that is along one of the eight bins, each encompassing three of the twenty-four zones
# Since these bins were cut into thirds, it is more accurate to simply use these segments than to create a whole new set of reference coordinates
mutate(Bin1.3 = SFZBinCoordAssign$ScaledY[2], #Length from Zone 1 to 3
Bin4.6 = abs(SFZBinCoordAssign$ScaledX[2] - SFZBinCoordAssign$ScaledX[3]), #Length from Zone 4 to 6
Bin7.9 = abs(SFZBinCoordAssign$ScaledY[4] - SFZBinCoordAssign$ScaledY[3]), #Length from Zone 7 to 9
Bin10.12 = abs(SFZBinCoordAssign$ScaledX[5] - SFZBinCoordAssign$ScaledX[4]), #Length from Zone 10 to 12
Bin13.15 = abs(SFZBinCoordAssign$ScaledX[6] - SFZBinCoordAssign$ScaledX[5]), #Length from Zone 13 to 15
Bin16.18 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[6]), #Length from Zone 16 to 18
Bin19.21 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 19 to 21
Bin22.24 = abs(SFZBinCoordAssign$ScaledX[8] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 22 to 24
# Binning the worker coordinates into a Zone
Zone =
# Zone 1
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY <= (1/3) * (Bin1.3), 1,
# Zone 2
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (1/3) * (Bin1.3) &
ScaledY <= (2/3) * (Bin1.3), 2,
# Zone 3
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (2/3) * (Bin1.3) &
ScaledY <= (Bin1.3), 3,
# Zone 4
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + (Bin4.6) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 4,
# Zone 5
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 5,
# Zone 6
if_else(ScaledX <= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX >= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 6,
# Zone 7
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY <= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)), 7,
# Zone 8
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)), 8,
# Zone 9
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + (Bin7.9), 9,
# Zone 10
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 10,
# Zone 11
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledX <= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 11,
# Zone 12
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX >= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 12,
# Zone13
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX <= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 13,
# Zone 14
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 14,
# Zone 15
if_else( ScaledX >= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 15,
# Zone 16
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledX <= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 16,
# Zone 17
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 17,
# Zone 18
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + Bin16.18 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 18,
# Zone 19
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] &
ScaledY >= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21), 19,
# Zone 20
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21) &
ScaledY >= BinCoordAssign$ScaledY[7] - (2/3) * (Bin19.21), 20,
# Zone 21
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] - (2/3) * (Bin19.21) &
ScaledY >= BinCoordAssign$ScaledY[7] - (Bin19.21), 21,
# Zone 22
if_else(ScaledX >= BinCoordAssign$ScaledX[9] + ((2/3) * (Bin22.24)) &
ScaledX <= BinCoordAssign$ScaledX[9] + (Bin22.24) &
ScaledY <= BinCoordAssign$ScaledY[9], 22,
# Zone 23
if_else(ScaledX <= BinCoordAssign$ScaledX[9] + ((2/3) * (Bin22.24)) &
ScaledX >= BinCoordAssign$ScaledX[9] + ((1/3) * (Bin22.24)) &
ScaledY <= BinCoordAssign$ScaledY[9], 23,
# Zone 24
if_else(ScaledX >= BinCoordAssign$ScaledX[9] &
ScaledX <= BinCoordAssign$ScaledX[9] + (1/3) * (Bin22.24) &
ScaledY <= BinCoordAssign$ScaledY[9], 24, 0
)))))))))))))))))))))))))
# CIRCLE NEST ZONES
Colony3BinnedCircleSFZ <- data_table %>%
filter(Colony == "3" & Nest == "Circle") %>%
mutate(Zone =
# Zone 1
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 1,
# Zone 2
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 2,
# Zone 3
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY <= BinCoordAssign$ScaledY[10], 3,
# Zone 4
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 4,
# Zone 5
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 5,
# Zone 6
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[10] &
ScaledY <= BinCoordAssign$ScaledY[11], 6,
# Zone 7
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 7,
# Zone 8
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 8,
# Zone 9
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[11] &
ScaledY <= BinCoordAssign$ScaledY[12], 9,
# Zone 10
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 10,
# Zone 11
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 11,
# Zone 12
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[12] &
ScaledY <= BinCoordAssign$ScaledY[13], 12,
# Zone 13
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 13,
# Zone 14
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[4] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 14,
# Zone 15
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[4] &
ScaledY >= BinCoordAssign$ScaledY[13] &
ScaledY <= BinCoordAssign$ScaledY[14], 15,
# Zone 16
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 16,
# Zone 17
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[3] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 17,
# Zone 18
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[3] &
ScaledY >= BinCoordAssign$ScaledY[14] &
ScaledY <= BinCoordAssign$ScaledY[15], 18,
# Zone 19
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 19,
# Zone 20
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[2] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 20,
# Zone 21
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[2] &
ScaledY >= BinCoordAssign$ScaledY[15] &
ScaledY <= BinCoordAssign$ScaledY[16], 21,
# Zone 22
if_else(ScaledX <= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 22,
# Zone 23
if_else(ScaledX >= 3.75 - BinCoord24Circ$AddValue[1] &
ScaledX <= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 23,
# Zone 24
if_else(ScaledX >= 3.75 + BinCoord24Circ$AddValue[1] &
ScaledY >= BinCoordAssign$ScaledY[16], 24, 0
)))))))))))))))))))))))))
# Join the site fidelity zone data sets
Colony3BinnedSFZ <<- full_join(Colony3BinnedTubeSFZ, Colony3BinnedCircleSFZ) %>%
select(Colony, Nest, Day, Bin, ScaledX, ScaledY, Zone, AntID)
}
# Run the zone assignment function on the usable color coordinates worker data set
CoordBinnedSFZ(SFZDataFull)
# COLONY 4
CoordBinnedSFZ <- function(data_table){
# Filtering the desired colony from the reference data sets
SFZBinCoordAssign <- BinCoordFull %>%
filter(Colony == "4")
BinCoordAssign <- BinCoordFull %>%
filter(Colony == "4")
BinCoord24Circ <- BinCoord24Circ %>%
filter(Colony == "4")
# Filtering the desired colony from the worker tube nest data sets
# Note that the site fidelity Bins will be referred to as "Zones" from here on
# TUBE NEST ZONES
Colony4BinnedTubeSFZ <- data_table %>%
filter(Colony == "4" & Nest == "Tube") %>%
# The following columns create reference points from the eight even area bin reference data set
# The goal is to produce a segment length that is along one of the eight bins, each encompassing three of the twenty-four zones
# Since these bins were cut into thirds, it is more accurate to simply use these segments than to create a whole new set of reference coordinates
mutate(Bin1.3 = SFZBinCoordAssign$ScaledY[2], #Length from Zone 1 to 3
Bin4.6 = abs(SFZBinCoordAssign$ScaledX[2] - SFZBinCoordAssign$ScaledX[3]), #Length from Zone 4 to 6
Bin7.9 = abs(SFZBinCoordAssign$ScaledY[4] - SFZBinCoordAssign$ScaledY[3]), #Length from Zone 7 to 9
Bin10.12 = abs(SFZBinCoordAssign$ScaledX[5] - SFZBinCoordAssign$ScaledX[4]), #Length from Zone 10 to 12
Bin13.15 = abs(SFZBinCoordAssign$ScaledX[6] - SFZBinCoordAssign$ScaledX[5]), #Length from Zone 13 to 15
Bin16.18 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[6]), #Length from Zone 16 to 18
Bin19.21 = abs(SFZBinCoordAssign$ScaledX[7] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 19 to 21
Bin22.24 = abs(SFZBinCoordAssign$ScaledX[8] - SFZBinCoordAssign$ScaledX[9]), #Length from Zone 22 to 24
# Binning the worker coordinates into a Zone
Zone =
# Zone 1
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY <= (1/3) * (Bin1.3), 1,
# Zone 2
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (1/3) * (Bin1.3) &
ScaledY <= (2/3) * (Bin1.3), 2,
# Zone 3
if_else(ScaledX >= SFZBinCoordAssign$ScaledX[2] &
ScaledX <= SFZBinCoordAssign$ScaledX[1] &
ScaledY >= (2/3) * (Bin1.3) &
ScaledY <= (Bin1.3), 3,
# Zone 4
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + (Bin4.6) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 4,
# Zone 5
if_else(ScaledX >= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX <= BinCoordAssign$ScaledX[3] + ((2/3) * (Bin4.6)) &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 5,
# Zone 6
if_else(ScaledX <= BinCoordAssign$ScaledX[3] + ((1/3) * (Bin4.6)) &
ScaledX >= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] &
ScaledY <= BinCoordAssign$ScaledY[2], 6,
# Zone 7
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY <= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)), 7,
# Zone 8
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((1/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)), 8,
# Zone 9
if_else(ScaledX >= BinCoordAssign$ScaledX[4] &
ScaledX <= BinCoordAssign$ScaledX[3] &
ScaledY >= BinCoordAssign$ScaledY[3] + ((2/3) * (Bin7.9)) &
ScaledY <= BinCoordAssign$ScaledY[3] + (Bin7.9), 9,
# Zone 10
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 10,
# Zone 11
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + ((1/3) * Bin10.12) &
ScaledX <= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 11,
# Zone 12
if_else(ScaledX <= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX >= BinCoordAssign$ScaledX[4] + ((2/3) * Bin10.12) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 12,
# Zone13
if_else(ScaledX >= BinCoordAssign$ScaledX[4] + Bin10.12 &
ScaledX <= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 13,
# Zone 14
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + ((1/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 14,
# Zone 15
if_else( ScaledX >= BinCoordAssign$ScaledX[5] + ((2/3) * Bin13.15) &
ScaledX <= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 15,
# Zone 16
if_else(ScaledX >= BinCoordAssign$ScaledX[5] + Bin13.15 &
ScaledX <= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 16,
# Zone 17
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((1/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 17,
# Zone 18
if_else(ScaledX >= BinCoordAssign$ScaledX[6] + ((2/3) * Bin16.18) &
ScaledX <= BinCoordAssign$ScaledX[6] + Bin16.18 &
ScaledY >= BinCoordAssign$ScaledY[4] &
ScaledY <= BinCoordAssign$ScaledY[5], 18,
# Zone 19
if_else(ScaledX >= BinCoordAssign$ScaledX[8] &
ScaledX <= BinCoordAssign$ScaledX[7] &
ScaledY <= BinCoordAssign$ScaledY[7] &
ScaledY >= BinCoordAssign$ScaledY[7] - (1/3) * (Bin19.21), 19,
# Zone 20