-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIH Fragmentation - Graphing [Big].R
2156 lines (1950 loc) · 197 KB
/
SIH Fragmentation - Graphing [Big].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
#binning and summarizing SR_Time dataframe so as to calculate mean time to extinction and make the 'wave of extinction style plots'
MeanExtTimeBin <- Biomass_Time %>%
group_by(Dispersal, Patch_remove, Scale, Rep) %>%
mutate(TimeStepRound = ceiling(TimeStep/5)) %>%
group_by(TimeStepRound,Dispersal,Patch_remove, Scale, Rep, Species, DelPatches)%>%
summarize(Mean_SR = mean(SR, na.rm = T)) %>%
group_by(Dispersal,Patch_remove, Scale, Rep, Species, DelPatches)%>%
mutate(NumExt = lag(Mean_SR) - Mean_SR) %>%
group_by(Dispersal, Patch_remove, Scale, TimeStepRound, Species, DelPatches) %>%
summarize(Mean_NumExt = mean(NumExt, na.rm = T), SD_NumExt = sd(NumExt, na.rm = T))
#log'd version
#this is figure 3 (4/14/2016)
ggplot(MeanExtTimeBin[MeanExtTimeBin$Species == nSpeciesMult[s] & MeanExtTimeBin$DelPatches==nPatchDel[p],],aes(x=TimeStepRound*5,y=Mean_NumExt,color=Scale,group=interaction(Scale, Patch_remove, Dispersal),fill=Scale,alpha = 0.1))+
geom_line()+
scale_x_log10()+
#geom_ribbon(aes(ymin=Mean_NumExt-SD_NumExt,ymax=Mean_NumExt+SD_NumExt),width=0.1,alpha = 0.1)+
geom_ribbon(aes(ymin=Mean_NumExt-SD_NumExt,ymax=Mean_NumExt+SD_NumExt),width=0.1, color = NA)+
facet_grid(Dispersal~Patch_remove)+
xlab("Time Step")+
ylab("Mean Number of Extinctions")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
geom_vline(x=predel_collecttime)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#graphing all of the SR and delpatch variants of figure 3, the forloop isn't working for some reason (did manually)
par(mfrow=c(length(nSpeciesMult),length(nPatchDel)))
for(s in 1:length(nSpeciesMult)){
for(p in 1:length(nPatchDel)){
ggplot(MeanExtTimeBin[MeanExtTimeBin$Species==nSpeciesMult[s] & MeanExtTimeBin$DelPatches==nPatchDel[p],],aes(x=TimeStepRound*5,y=Mean_NumExt,color=Scale,group=interaction(Scale, Patch_remove, Dispersal),fill=Scale,alpha = 0.1))+
geom_line()+
scale_x_log10()+
#geom_ribbon(aes(ymin=Mean_NumExt-SD_NumExt,ymax=Mean_NumExt+SD_NumExt),width=0.1,alpha = 0.1)+
geom_ribbon(aes(ymin=Mean_NumExt-SD_NumExt,ymax=Mean_NumExt+SD_NumExt),width=0.1, color = NA)+
facet_grid(Dispersal~Patch_remove)+
xlab("Time Step")+
ylab("Mean Number of Extinctions")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
geom_vline(x=predel_collecttime)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
}
}
##Calculating proportion of species richness remaining, as calculated from the initial equilibrium number of species in the community
PropSR_Time <- data.frame(Rep=rep(1:reps, each = length(sampleV)*length(removeV)*length(dispV)*2*length(nSpeciesMult)*length(nPatchDel)),
Dispersal=rep(dispV, each = length(removeV)*length(sampleV)*2*length(nSpeciesMult)*length(nPatchDel)),
Patch_remove=rep(factor(removeV,levels = c("Min betweenness","Random","Max betweenness"),ordered = T), each = length(sampleV)*2*length(nSpeciesMult)*length(nPatchDel)),
Species = rep(nSpeciesMult, each = length(sampleV)*2*length(nPatchDel)), DelPatches = rep(nPatchDel, each = length(sampleV)*2), Scale=rep(c("Local","Regional"), each = length(sampleV)),TimeStep = rep(1:length(sampleV)), SR = NA)
#need to figure a better way, that doesn't involve forloops, to add in elements of the above dataframe
for(o in 1:length(dispV)){
for(w in 1:length(removeV)){
for(s in 1:length(nSpeciesMult)){
for(p in 1:length(nPatchDel)){
for(j in 1:reps){
PropSR_Time$SR[PropSR_Time$Scale == "Regional" & PropSR_Time$Dispersal == dispV[o] & PropSR_Time$Patch_remove == removeV[w] & PropSR_Time$Species == nSpeciesMult[s] & PropSR_Time$DelPatches == nPatchDel[p] & PropSR_Time$Rep == j]<- Biomass_Time$SR[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j]/Biomass_Time$SR[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
PropSR_Time$SR[PropSR_Time$Scale == "Local" & PropSR_Time$Dispersal == dispV[o] & PropSR_Time$Patch_remove == removeV[w] & PropSR_Time$Species == nSpeciesMult[s] & PropSR_Time$DelPatches == nPatchDel[p] & PropSR_Time$Rep == j]<- Biomass_Time$SR[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j]/Biomass_Time$SR[SR_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
}
}
}
}
}
PropSRTimeSummd <- summarise(group_by(PropSR_Time, Dispersal, Patch_remove, TimeStep, Species, DelPatches, Scale), Mean_SR = mean(SR, na.rm=T), SD_SR = sd(SR, na.rm = T))
#this is figure 2 (4/14/2016) (mean proportional species richness over time, across all scenarios)
require(ggplot2)
#SR over time plots
ggplot(PropSRTimeSummd[PropSRTimeSummd$Species==nSpeciesMult[s]&PropSRTimeSummd$DelPatches==nPatchDel[p],],aes(x=TimeStep,y=Mean_SR,color=Scale,group=interaction(Scale, Patch_remove, Dispersal),fill=Scale, alpha = 0.1))+
#geom_point()+
geom_line()+
scale_x_log10()+
geom_ribbon(aes(ymin=Mean_SR-SD_SR,ymax=Mean_SR+SD_SR),width=0.1, color = NA)+
xlab("Time Step")+
ylab("Mean Proportion of Species Richness")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#adding in percent species loss metric into ED_data dataframe (and percent change in biomass, percent change in CV)
for(o in 1:length(dispV)){
for(w in 1:length(removeV)){
for(j in 1:reps){
for(s in 1:length(nSpeciesMult)){
for(p in 1:length(nPatchDel)){
Numpredel <- Biomass_Time$SR[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
Biomasspredel <- Biomass_Time$Biomass[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
CVpredel <- Biomass_Time$CVTime[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
ED_data$PercentLoss[ED_data$Scale == "Regional" & ED_data$Dispersal == dispV[o] & ED_data$Patch_remove == removeV[w] & ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p] & ED_data$Rep == j]<- (Numpredel - Biomass_Time$SR[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][length(sampleV)])/Numpredel
#^ i feel like this line could be replaced with ED_data$SRLoss[...]/Numpredel now that the SRLoss metric only looks at what's going on after patch deletion though not sure about this
ED_data$PercentBmasschange[ED_data$Scale == "Regional" & ED_data$Dispersal == dispV[o] & ED_data$Patch_remove == removeV[w] & ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p] & ED_data$Rep == j]<- (Biomasspredel - Biomass_Time$Biomass[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][length(sampleV)])/Biomasspredel
ED_data$PercentCVchange[ED_data$Scale == "Regional" & ED_data$Dispersal == dispV[o] & ED_data$Patch_remove == removeV[w] & ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p] & ED_data$Rep == j]<- (CVpredel - Biomass_Time$CVTime[Biomass_Time$Scale == "Regional" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][length(sampleV) - ePeriod/samplelength])/CVpredel
Numpredel <- Biomass_Time$SR[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
Biomasspredel <- Biomass_Time$Biomass[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
CVpredel <- Biomass_Time$CVTime[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][predel_collecttime]
ED_data$PercentLoss[ED_data$Scale == "Local" & ED_data$Dispersal == dispV[o] & ED_data$Patch_remove == removeV[w] & ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p] & ED_data$Rep == j]<- (Numpredel - Biomass_Time$SR[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][length(sampleV)])/Numpredel
#^ i feel like this line could be replaced with ED_data$SRLoss[...]/Numpredel now that the SRLoss metric only looks at what's going on after patch deletion though not sure about this
ED_data$PercentBmasschange[ED_data$Scale == "Local" & ED_data$Dispersal == dispV[o] & ED_data$Patch_remove == removeV[w] & ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p] & ED_data$Rep == j]<- (Biomasspredel - Biomass_Time$Biomass[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][length(sampleV)])/Biomasspredel
ED_data$PercentCVchange[ED_data$Scale == "Local" & ED_data$Dispersal == dispV[o] & ED_data$Patch_remove == removeV[w] & ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p] & ED_data$Rep == j]<- (CVpredel - Biomass_Time$CVTime[Biomass_Time$Scale == "Local" & Biomass_Time$Dispersal == dispV[o] & Biomass_Time$Patch_remove == removeV[w] & Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Rep == j][length(sampleV) - ePeriod/samplelength])/CVpredel
}
}
}
}
}
EDdata_avg2 <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches), Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLoss = range(SRLoss, na.rm = T)[1], Highest_SRLoss = range(SRLoss, na.rm = T)[2],
Mean_LastDebtTime = mean(LastDebtTime, na.rm=T), SD_LastDebtTime = sd(LastDebtTime, na.rm = T),Lowest_LastDebtTime = range(LastDebtTime, na.rm = T)[1], Highest_LastDebtTime = range(LastDebtTime, na.rm = T)[2], Mean_PercentLoss = mean(PercentLoss, na.rm=T), SD_PercentLoss = sd(PercentLoss, na.rm = T), Lowest_PercentLoss = range(PercentLoss, na.rm = T)[1], Highest_PercentLoss = range(PercentLoss, na.rm = T)[2])
#figure 4 (4/14/2016)
#percent of species lost vs time until last extinction plot
ggplot(EDdata_avg2[EDdata_avg2$Species == nSpeciesMult[s] & EDdata_avg2$DelPatches == nPatchDel[p],],aes(x=Mean_LastDebtTime,y=Mean_PercentLoss,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Last Extinction")+
ylab("Percentage of Species Lost")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_PercentLoss,ymax=Highest_PercentLoss),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#summarizing all of the different metrics (biomass, cv, sr) to capture the mean percent change/loss and their 95% quantiles
EDavg <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches),
Mean_PercentLoss = mean(PercentLoss, na.rm=T), SD_PercentLoss = sd(PercentLoss, na.rm = T), Lowest_PercentLoss = quantile(PercentLoss, probs = 0.025, na.rm=T, names = F), Highest_PercentLoss = quantile(PercentLoss, probs = 0.975, na.rm=T, names = F),
Mean_LastDebtTime = mean(LastDebtTime, na.rm=T), SD_LastDebtTime = sd(LastDebtTime, na.rm = T), Lowest_LastDebtTime = quantile(LastDebtTime, probs = 0.025, na.rm=T, names = F), Highest_LastDebtTime = quantile(LastDebtTime, probs = 0.975, na.rm=T, names = F),
Mean_PercentBmassChange = mean(PercentBmassChange, na.rm=T), SD_PercentBmassChange = sd(PercentBmassChange, na.rm = T), Lowest_PercentBmassChange = quantile(PercentBmassChange, probs = 0.025, na.rm=T, names = F), Highest_PercentBmassChange = quantile(PercentBmassChange, probs = 0.975, na.rm=T, names = F),
Mean_LagTime = mean(LagTime, na.rm=T), SD_LagTime = sd(LagTime, na.rm=T), Lowest_LagTime=quantile(LagTime, probs = 0.025, na.rm=T, names = F), Highest_LagTime=quantile(LagTime, probs = 0.975, na.rm=T, names = F),
Mean_PercentCVChange = mean(PercentCVChange, na.rm=T), SD_PercentCVChange = sd(PercentCVChange, na.rm = T), Lowest_PercentCVChange = quantile(PercentCVChange, probs = 0.025, na.rm=T, names = F), Highest_PercentCVChange = quantile(PercentCVChange, probs = 0.975, na.rm=T, names = F),
Mean_CVLagTime = mean(CVLagTime, na.rm=T), SD_CVLagTime = sd(CVLagTime, na.rm=T), Lowest_CVLagTime=quantile(CVLagTime, probs = 0.025, na.rm=T, names = F), Highest_CVLagTime=quantile(CVLagTime, probs = 0.975, na.rm=T, names = F))
#SR plot
ggplot(EDavg[EDavg$Species == nSpeciesMult[s] & EDavg$DelPatches == nPatchDel[p],],aes(x=Mean_LastDebtTime,y=Mean_PercentLoss,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Last Extinction")+
ylab("Percentage of Species Lost")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_PercentLoss,ymax=Highest_PercentLoss),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#SR tryptic-style plot
ggplot(EDavg[EDavg$Species == nSpeciesMult[s],],aes(x=Mean_LastDebtTime,y=Mean_PercentLoss,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal, DelPatches)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Last Extinction")+
ylab("Percentage of Species Lost")+
#ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_PercentLoss,ymax=Highest_PercentLoss),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~DelPatches)+ #optional: facet_grid(Scale~DelPatches, scales = "free_x")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#Biomass plot
ggplot(EDavg[EDavg$Species == nSpeciesMult[s] & EDavg$DelPatches == nPatchDel[p],],aes(x=Mean_LagTime,y=Mean_PercentBmassChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Biomass Stabilizes")+
ylab("Percentage of Biomass Lost")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_PercentBmassChange,ymax=Highest_PercentBmassChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LagTime,xmax=Highest_LagTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#Biomass plot (tryptic style)
ggplot(EDavg[EDavg$Species == nSpeciesMult[s],],aes(x=Mean_LagTime,y=Mean_PercentBmassChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal, DelPatches)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Biomass Stabilizes")+
ylab("Percentage of Biomass Lost")+
#ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_PercentBmassChange,ymax=Highest_PercentBmassChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LagTime,xmax=Highest_LagTime),width=0.1, linetype = 2)+
facet_grid(Scale~DelPatches)+
#optional: facet_grid(Scale~DelPatches, scales = "free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#CV plot
ggplot(EDavg[EDavg$Species == nSpeciesMult[s] & EDavg$DelPatches == nPatchDel[p],],aes(x=Mean_CVLagTime,y=-Mean_PercentCVChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until CV Stabilizes")+
ylab("Percentage of CV Gained")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=-Lowest_PercentCVChange,ymax=-Highest_PercentCVChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_CVLagTime,xmax=Highest_CVLagTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#CV plot tryptic-style
ggplot(EDavg[EDavg$Species == nSpeciesMult[s],],aes(x=Mean_CVLagTime,y=-Mean_PercentCVChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal, DelPatches)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until CV Stabilizes")+
ylab("Percentage of CV Gained")+
#ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=-Lowest_PercentCVChange,ymax=-Highest_PercentCVChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_CVLagTime,xmax=Highest_CVLagTime),width=0.1, linetype = 2)+
facet_grid(Scale~DelPatches)+ #optional: facet_grid(Scale~DelPatches, scales = "free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#not looking at percent changes...(but otherwise, same as the non-tryptic graphs above)
EDavg2 <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches),
Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLoss=quantile(SRLoss, probs = 0.025, na.rm=T, names = F), Highest_SRLoss=quantile(SRLoss, probs = 0.975, na.rm=T, names = F),
Mean_LastDebtTime = mean(LastDebtTime, na.rm=T), SD_LastDebtTime = sd(LastDebtTime, na.rm = T),
Lowest_LastDebtTime=quantile(LastDebtTime, probs = 0.025, na.rm=T, names = F), Highest_LastDebtTime=quantile(LastDebtTime, probs = 0.975, na.rm=T, names = F),
Mean_BiomassChange = mean(BiomassChange, na.rm=T), SD_BiomassChange = sd(BiomassChange, na.rm = T), Lowest_BiomassChange=quantile(BiomassChange, probs = 0.025, na.rm=T, names = F), Highest_BiomassChange=quantile(CVLagTime, probs = 0.975, na.rm=T, names = F),
Mean_LagTime = mean(LagTime, na.rm=T), SD_LagTime = sd(LagTime, na.rm=T), Lowest_LagTime=quantile(LagTime, probs = 0.025, na.rm=T, names = F), Highest_LagTime=quantile(LagTime, probs = 0.975, na.rm=T, names = F),
Mean_CVChange = mean(CVChange, na.rm=T), SD_CVChange = sd(CVChange, na.rm = T), Lowest_CVChange=quantile(CVChange, probs = 0.025, na.rm=T, names = F), Highest_CVChange=quantile(CVChange, probs = 0.975, na.rm=T, names = F),
Mean_CVLagTime = mean(CVLagTime, na.rm=T), SD_CVLagTime = sd(CVLagTime, na.rm=T), Lowest_CVLagTime=quantile(CVLagTime, probs = 0.025, na.rm=T, names = F), Highest_CVLagTime=quantile(CVLagTime, probs = 0.975, na.rm=T, names = F))
#SR plot
ggplot(EDavg2[EDavg2$Species == nSpeciesMult[s] & EDavg2$DelPatches == nPatchDel[p],],aes(x=Mean_LastDebtTime,y=Mean_SRLoss,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Last Extinction")+
ylab("Species Lost")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_SRLoss,ymax=Highest_SRLoss),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#Biomass plot
ggplot(EDavg2[EDavg2$Species == nSpeciesMult[s] & EDavg2$DelPatches == nPatchDel[p],],aes(x=Mean_LagTime,y=Mean_BiomassChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Biomass Stabilizes")+
ylab("Change in Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_BiomassChange,ymax=Highest_BiomassChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LagTime,xmax=Highest_LagTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#CV plot
ggplot(EDavg2[EDavg2$Species == nSpeciesMult[s] & EDavg2$DelPatches == nPatchDel[p],],aes(x=Mean_CVLagTime,y=Mean_CVChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until CV Stabilizes")+
ylab("CV Gained")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_CVChange,ymax=Highest_CVChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_CVLagTime,xmax=Highest_CVLagTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(ED_data[ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p],],aes(x=LagTime/(ePeriod/samplelength),y=BiomassChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 2)+
scale_shape_manual(values=c(15,19, 17))+
xlab("Time Until Re-Equilibrium")+
ylab("Change in Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
#geom_errorbar(aes(ymin=Lowest_PercentLoss,ymax=Highest_PercentLoss),width=0.1, linetype = 2)+
#geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~., scales = "free_y")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#this graph is an attempt at a line plot, but it really doesn't work very well
ggplot(ED_data[ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p],],aes(x=LagTime/(ePeriod/samplelength),y=BiomassChange,color=interaction(factor(Dispersal), Patch_remove),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "Paired")+ #or "Paired"
geom_line(aes(group = interaction(factor(Dispersal), Patch_remove)))+
xlab("Time Until Re-Equilibrium")+
ylab("Change in Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
#geom_errorbar(aes(ymin=Lowest_PercentLoss,ymax=Highest_PercentLoss),width=0.1, linetype = 2)+
#geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#also doesn't really work :(
ggplot(ED_data[ED_data$Species == nSpeciesMult[s] & ED_data$DelPatches == nPatchDel[p],],aes(x=LagTime/(ePeriod/samplelength),y=BiomassChange,color=interaction(factor(Dispersal), Patch_remove),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "Paired")+ #or "Paired"
geom_point(aes(group = interaction(factor(Dispersal), Patch_remove)))+
stat_smooth(method = "lm")+
xlab("Time Until Re-Equilibrium")+
ylab("Change in Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
#geom_errorbar(aes(ymin=Lowest_PercentLoss,ymax=Highest_PercentLoss),width=0.1, linetype = 2)+
#geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~.)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
EDdata_avg <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches), Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T),
Mean_LastDebtTime = mean(LastDebtTime, na.rm=T), SD_LastDebtTime = sd(LastDebtTime, na.rm = T), Mean_Mean_Bmass = mean(Mean_Bmass, na.rm=T), SD_Mean_Bmass = sd(Mean_Bmass, na.rm=T),
Mean_CVBmass = mean(CV_Bmass, na.rm=T), SD_CVBmass = sd(CV_Bmass, na.rm = T), Mean_BiomassChange = mean(BiomassChange, na.rm=T), SD_BiomassChange = sd(BiomassChange, na.rm = T), Lowest_BiomassChange=range(BiomassChange,na.rm=T)[1], Highest_BiomassChange=range(BiomassChange,na.rm=T)[2], Mean_LagTime = mean(LagTime, na.rm=T), SD_LagTime = sd(LagTime, na.rm=T), Lowest_LagTime=range(LagTime,na.rm=T)[1], Highest_LagTime=range(LagTime,na.rm=T)[2])
ggplot(EDdata_avg[EDdata_avg$Species == nSpeciesMult[s] & EDdata_avg$DelPatches == nPatchDel[p],],aes(x=Mean_LagTime,y=Mean_BiomassChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
scale_shape_manual(values=c(15,19, 17))+
xlab("Time Until Re-Equilibrium")+
ylab("Change in Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Mean_BiomassChange - SD_BiomassChange,ymax=Mean_BiomassChange + SD_BiomassChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Mean_LagTime - SD_LagTime,xmax=Mean_LagTime + SD_LagTime),width=0.1, linetype = 2)+
facet_grid(Scale~.,scales = "free_y")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(EDdata_avg[EDdata_avg$Species == nSpeciesMult[s] & EDdata_avg$DelPatches == nPatchDel[p],],aes(x=Mean_LagTime,y=Mean_BiomassChange,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
scale_shape_manual(values=c(15,19, 17))+
xlab("Time Until Re-Equilibrium")+
ylab("Change in Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Lowest_BiomassChange,ymax= Highest_BiomassChange),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LagTime,xmax=Highest_LagTime),width=0.1, linetype = 2)+
facet_grid(Scale~.,scales = "free_y")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(EDdata_avg[EDdata_avg$Species == nSpeciesMult[s] & EDdata_avg$DelPatches == nPatchDel[p],],aes(x=Mean_Mean_Bmass,y=Mean_CVBmass,color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal)))+
scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
scale_shape_manual(values=c(15,19, 17))+
xlab("Mean Biomass")+
ylab("CV Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=Mean_CVBmass - SD_CVBmass,ymax=Mean_CVBmass + SD_CVBmass),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Mean_Mean_Bmass - SD_Mean_Bmass,xmax=Mean_Mean_Bmass + SD_Mean_Bmass),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Scale~.,scales = "free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#change in _____ vs # of patches deleted
#CV change shows up underneath SR loss
ggplot(ED_data[ED_data$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove)))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = CVChange, color = "CV Change", size = 4))+
#geom_point(aes(size = 4))+
geom_point(aes(y = BiomassChange, color = "Biomass Change", size = 4))+
geom_point(aes(y = SRLoss, color = "SR Loss", size = 4))+
#scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("Change")+
ggtitle(paste(nSpeciesMult[s], "Species Initially"))+
#geom_errorbar(aes(ymin=Mean_CVBmass - SD_CVBmass,ymax=Mean_CVBmass + SD_CVBmass),width=0.1, linetype = 2)+
#geom_errorbarh(aes(xmin=Mean_Mean_Bmass - SD_Mean_Bmass,xmax=Mean_Mean_Bmass + SD_Mean_Bmass),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#change in _____ (greater than that due to fake patch deletion) vs # of patches deleted
ggplot(ED_data[ED_data$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove)))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = CVChange-CVChangeNoDel, color = "CV Change", size = 4))+
#geom_point(aes(size = 4))+
geom_point(aes(y = BiomassChange-BmassLossNoDel, color = "Biomass Change", size = 4))+
geom_point(aes(y = SRLoss-SRLossNoDel, color = "SR Loss", size = 4))+
scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("Change")+
ggtitle(paste(nSpeciesMult[s], "Species Initially"))+
#geom_errorbar(aes(ymin=Mean_CVBmass - SD_CVBmass,ymax=Mean_CVBmass + SD_CVBmass),width=0.1, linetype = 2)+
#geom_errorbarh(aes(xmin=Mean_Mean_Bmass - SD_Mean_Bmass,xmax=Mean_Mean_Bmass + SD_Mean_Bmass),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
EDdata_avgchange <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches), Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLoss=quantile(SRLoss, probs = 0.025, na.rm=T, names = F), Highest_SRLoss=quantile(SRLoss, probs = 0.975, na.rm=T, names = F),
Mean_SRLossNoDel = mean(SRLossNoDel, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_BiomassChange = mean(BiomassChange, na.rm=T), SD_BiomassChange = sd(BiomassChange, na.rm = T), Lowest_BiomassChange=quantile(BiomassChange, probs = 0.025, na.rm=T, names = F), Highest_BiomassChange=quantile(BiomassChange, probs = 0.975, na.rm=T, names = F),
Mean_BmassLossNoDel = mean(BmassLossNoDel, na.rm=T), SD_BmassLossNoDel = sd(BmassLossNoDel, na.rm = T), Lowest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_CVChange = mean(CVChange, na.rm=T), SD_CVChange = sd(CVChange, na.rm = T), Lowest_CVChange=quantile(CVChange, probs = 0.025, na.rm=T, names = F), Highest_CVChange=quantile(CVChange, probs = 0.975, na.rm=T, names = F), Mean_CVChangeNoDel = mean(CVChangeNoDel, na.rm=T), SD_CVChangeNoDel = sd(CVChangeNoDel, na.rm = T), Lowest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.025, na.rm=T, names = F), Highest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.975, na.rm=T, names = F))
#change in _____ vs # of patches deleted
#CV change shows up underneath SR loss, need to get the error bars to work urgh
ggplot(EDdata_avgchange[EDdata_avgchange$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove), size = 2))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = Mean_CVChange, color = "CV Change"))+
#geom_point(aes(size = 4))+
geom_point(aes(y = Mean_BiomassChange, color = "Biomass Change"))+
geom_point(aes(y = Mean_SRLoss, color = "SR Loss"))+
scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("Total Change")+
scale_y_log10()+
#ggtitle(paste(nSpeciesMult[s], "Species Initially"))+ <- I think I'm sticking with 11 species for the time being
#geom_errorbar(aes(ymin=Lowest_CVChange, ymax=Highest_CVChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_BiomassChange, ymax=Highest_BiomassChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_SRLoss, ymax=Highest_SRLoss),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#change in _____ (greater than that due to fake patch deletion) vs # of patches deleted
ggplot(EDdata_avgchange[EDdata_avgchange$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove), size = 2))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = Mean_CVChange - Mean_CVChangeNoDel, color = "CV Change"))+
#geom_point(aes(size = 4))+
geom_point(aes(y = Mean_BiomassChange - Mean_BmassLossNoDel, color = "Biomass Change"))+
geom_point(aes(y = Mean_SRLoss - Mean_SRLossNoDel, color = "SR Loss"))+
scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("Change due to Indirect Effects")+
scale_y_log10()+
#ggtitle(paste(nSpeciesMult[s], "Species Initially"))+ <- I think I'm sticking with 11 species for the time being
#geom_errorbar(aes(ymin=Lowest_CVChange, ymax=Highest_CVChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_BiomassChange, ymax=Highest_BiomassChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_SRLoss, ymax=Highest_SRLoss),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#abs(change in _____) (greater than that due to fake patch deletion) vs # of patches deleted
ggplot(EDdata_avgchange[EDdata_avgchange$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove), size = 2))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = abs(Mean_CVChange - Mean_CVChangeNoDel), color = "CV Change"))+
#geom_point(aes(size = 4))+
geom_point(aes(y = abs(Mean_BiomassChange - Mean_BmassLossNoDel), color = "Biomass Change"))+
geom_point(aes(y = abs(Mean_SRLoss - Mean_SRLossNoDel), color = "SR Loss"))+
scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("abs(Change)")+
scale_y_log10()+
#ggtitle(paste(nSpeciesMult[s], "Species Initially"))+ <- I think I'm sticking with 11 species for the time being
#geom_errorbar(aes(ymin=Lowest_CVChange, ymax=Highest_CVChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_BiomassChange, ymax=Highest_BiomassChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_SRLoss, ymax=Highest_SRLoss),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#change in ______ (due to fake patch deletion only)
ggplot(EDdata_avgchange[EDdata_avgchange$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove), size = 2))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = Mean_CVChangeNoDel, color = "CV Change"))+
#geom_point(aes(size = 4))+
geom_point(aes(y = Mean_BmassLossNoDel, color = "Biomass Change"))+
geom_point(aes(y = Mean_SRLossNoDel, color = "SR Loss"))+
scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("Change Due to Patch Del")+
scale_y_log10()+
#ggtitle(paste(nSpeciesMult[s], "Species Initially"))+ <- I think I'm sticking with 11 species for the time being
#geom_errorbar(aes(ymin=Lowest_CVChange, ymax=Highest_CVChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_BiomassChange, ymax=Highest_BiomassChange),width=0.1, linetype = 2)+
#geom_errorbar(aes(ymin=Lowest_SRLoss, ymax=Highest_SRLoss),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#summary of all measures in the ED_data dataframe other than the Mean_Bmass and CV_Bmass measures
EDdata_avgall <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches), Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLoss=quantile(SRLoss, probs = 0.025, na.rm=T, names = F), Highest_SRLoss=quantile(SRLoss, probs = 0.975, na.rm=T, names = F),
Mean_SRLossNoDel = mean(SRLossNoDel, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_LastDebtTime = mean(LastDebtTime, na.rm=T), SD_LastDebtTime = sd(LastDebtTime, na.rm = T), Lowest_LastDebtTime=quantile(LastDebtTime, probs = 0.025, na.rm=T, names = F), Highest_LastDebtTime=quantile(LastDebtTime, probs = 0.975, na.rm=T, names = F),
Mean_PercentLoss = mean(PercentLoss, na.rm=T), SD_PercentLoss = sd(PercentLoss, na.rm = T), Lowest_PercentLoss=quantile(PercentLoss, probs = 0.025, na.rm=T, names = F), Highest_PercentLoss=quantile(PercentLoss, probs = 0.975, na.rm=T, names = F),
Mean_BiomassChange = mean(BiomassChange, na.rm=T), SD_BiomassChange = sd(BiomassChange, na.rm = T), Lowest_BiomassChange=quantile(BiomassChange, probs = 0.025, na.rm=T, names = F), Highest_BiomassChange=quantile(BiomassChange, probs = 0.975, na.rm=T, names = F),
Mean_BmassLossNoDel = mean(BmassLossNoDel, na.rm=T), SD_BmassLossNoDel = sd(BmassLossNoDel, na.rm = T), Lowest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_LagTime = mean(LagTime, na.rm=T), SD_LagTime = sd(LagTime, na.rm = T), Lowest_LagTime=quantile(LagTime, probs = 0.025, na.rm=T, names = F), Highest_LagTime=quantile(LagTime, probs = 0.975, na.rm=T, names = F),
Mean_PercentBmassChange = mean(PercentBmassChange, na.rm=T), SD_PercentBmassChange = sd(PercentBmassChange, na.rm = T), Lowest_PercentBmassChange=quantile(PercentBmassChange, probs = 0.025, na.rm=T, names = F), Highest_PercentBmassChange=quantile(PercentBmassChange, probs = 0.975, na.rm=T, names = F),
Mean_CVChange = mean(CVChange, na.rm=T), SD_CVChange = sd(CVChange, na.rm = T), Lowest_CVChange=quantile(CVChange, probs = 0.025, na.rm=T, names = F), Highest_CVChange=quantile(CVChange, probs = 0.975, na.rm=T, names = F), Mean_CVChangeNoDel = mean(CVChangeNoDel, na.rm=T), SD_CVChangeNoDel = sd(CVChangeNoDel, na.rm = T), Lowest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.025, na.rm=T, names = F), Highest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.975, na.rm=T, names = F), Mean_CVLagTime = mean(CVLagTime, na.rm=T), SD_CVLagTime = sd(CVLagTime, na.rm = T), Lowest_CVLagTime=quantile(CVLagTime, probs = 0.025, na.rm=T, names = F), Highest_CVLagTime=quantile(CVLagTime, probs = 0.975, na.rm=T, names = F), Mean_PercentCVChange = mean(PercentCVChange, na.rm=T), SD_PercentCVChange = sd(PercentCVChange, na.rm = T), Lowest_PercentCVChange=quantile(PercentCVChange, probs = 0.025, na.rm=T, names = F), Highest_PercentCVChange=quantile(PercentCVChange, probs = 0.975, na.rm=T, names = F))
#SR tryptic-style plot (change due to effect alone)
ggplot(EDdata_avgall[EDdata_avgall$Species == nSpeciesMult[s],],aes(x=Mean_LastDebtTime,y=(Mean_SRLoss - Mean_SRLossNoDel),color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal, DelPatches)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Last Extinction")+
ylab("Species Lost due to Patch Deletion Effects")+
#ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=(Lowest_SRLoss - Lowest_SRLossNoDel),ymax=(Highest_SRLoss - Highest_SRLossNoDel)),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LastDebtTime,xmax=Highest_LastDebtTime),width=0.1, linetype = 2)+
facet_grid(Scale~DelPatches)+ #optional: facet_grid(Scale~DelPatches, scales = "free_x")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#SR tryptic-style plot (change due to deletion alone) <- removed because doesn't make sense to plot this way, no delay in how the change in SR is calculated
#Biomass plot (tryptic style)
ggplot(EDdata_avgall[EDdata_avgall$Species == nSpeciesMult[s],],aes(x=Mean_LagTime,y=(Mean_BiomassChange - Mean_BmassLossNoDel),color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal, DelPatches)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until Biomass Stabilizes")+
ylab("Biomass Lost due to Patch Deletion Effects")+
#ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=(Lowest_BiomassChange - Lowest_BmassLossNoDel),ymax=(Highest_BiomassChange - Highest_BmassLossNoDel)),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_LagTime,xmax=Highest_LagTime),width=0.1, linetype = 2)+
facet_grid(Scale~DelPatches)+
#optional: facet_grid(Scale~DelPatches, scales = "free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#CV plot tryptic-style
ggplot(EDdata_avgall[EDdata_avgall$Species == nSpeciesMult[s],],aes(x=Mean_CVLagTime,y=(Mean_CVChange - Mean_CVChangeNoDel),color=factor(Dispersal),group=interaction(Scale, Patch_remove, Dispersal, DelPatches)))+
scale_color_brewer("Dispersal Level", palette = "BrBG")+ #or "Paired"
geom_point(aes(shape = factor(Patch_remove)), size = 4)+
#scale_x_log10()+
#scale_shape_manual(values=c(25,19, 17))+
scale_shape_manual(values=c(15,19, 17))+
#scale_alpha_discrete(range = c(0.4,1))+
xlab("Time Until CV Stabilizes")+
ylab("Change in CV Due to Effects of Patch Deletion")+
#ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_errorbar(aes(ymin=(Lowest_CVChange - Lowest_CVChangeNoDel),ymax=(Highest_CVChange - Highest_CVChangeNoDel)),width=0.1, linetype = 2)+
geom_errorbarh(aes(xmin=Lowest_CVLagTime,xmax=Highest_CVLagTime),width=0.1, linetype = 2)+
facet_grid(Scale~DelPatches)+ #optional: facet_grid(Scale~DelPatches, scales = "free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#lag time vs # of patches deleted
ggplot(EDdata_avgall[EDdata_avgall$Species == nSpeciesMult[s],],aes(x=factor(DelPatches),group=interaction(Scale, Patch_remove, Dispersal),shape = factor(Patch_remove), size = 2))+
#scale_color_brewer("Dispersal Level", palette = "Paired")+
geom_point(aes(y = Mean_CVLagTime, color = "CV"))+
#geom_point(aes(size = 4))+
geom_point(aes(y = Mean_LagTime, color = "Biomass"))+
geom_point(aes(y = Mean_LastDebtTime, color = "SR"))+
scale_shape_manual(values=c(15,19, 17))+
xlab("Number of Patches Deleted")+
ylab("Lag Time")+
scale_y_log10()+
#ggtitle(paste(nSpeciesMult[s], "Species Initially"))+ <- I think I'm sticking with 11 species for the time being
geom_errorbar(aes(ymin=Lowest_CVLagTime, ymax=Highest_CVLagTime),width=0.1, linetype = 2)+
geom_errorbar(aes(ymin=Lowest_LagTime, ymax=Highest_LagTime),width=0.1, linetype = 2)+
geom_errorbar(aes(ymin=Lowest_LastDebtTime, ymax=Highest_LastDebtTime),width=0.1, linetype = 2)+
#facet_grid(Scale~.,scales = "free_y")+
facet_grid(Dispersal~Scale)+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#looking at the proportion of biomass due to the different metacommunity processes
#binning the metadynamics data because otherwise just see massively fluctuating sine waves
MetaDynAvg_Bin <- Meta_dyn_reps %>%
group_by(Dispersal, Patch_remove, Dynamic, Species, DelPatches, Rep) %>%
mutate(TimeStepRound = ceiling(TimeStep/20)) %>%
group_by(TimeStepRound, Dispersal,Patch_remove, Dynamic, Species, DelPatches, Rep)%>%
summarize(Mean_Proportion = mean(Proportion, na.rm = T)) %>%
group_by(Dispersal, Patch_remove, Dynamic, Species, DelPatches, TimeStepRound) %>%
summarize(SD_Proportion = sd(Mean_Proportion, na.rm = T), Mean_Proportion = mean(Mean_Proportion, na.rm = T))
#supplementary materials figure 2 (4/3/2016)
ggplot(MetaDynAvg_Bin[MetaDynAvg_Bin$Species == nSpeciesMult[s] & MetaDynAvg_Bin$DelPatches == nPatchDel[p],],aes(x=TimeStepRound,y=Mean_Proportion,color=Dynamic,fill = Dynamic))+
xlab("Time Step")+
ylab("Proportion of Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_line()+
scale_x_log10()+
facet_grid(Dispersal~Patch_remove)+
geom_vline(x=predel_collecttime/20)+
theme_bw(base_size = 18)+ #gets rid of grey background
geom_ribbon(aes(ymin=Mean_Proportion-SD_Proportion,ymax=Mean_Proportion+SD_Proportion), alpha = 0.2, color = NA)+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
##Plotting Biomass
require(ggplot2)
#Raw Biomass Plot
ggplot(Biomass_Time[Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p],],aes(x=TimeStep,y=Biomass,color=Scale,group=interaction(Scale, Patch_remove, Dispersal),fill=Scale, alpha = 0.1))+
#geom_point()+
geom_line()+
scale_x_log10()+
#geom_ribbon(aes(ymin=Mean_SR-SD_SR,ymax=Mean_SR+SD_SR),width=0.1, color = NA)+
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(Biomass_Time[Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Scale == "Regional",],aes(x=TimeStep,y=CVTime,group=interaction(Patch_remove, Dispersal),fill=Scale, alpha = 0.1))+
#geom_point()+
geom_line()+
scale_x_log10()+
#geom_ribbon(aes(ymin=Mean_SR-SD_SR,ymax=Mean_SR+SD_SR),width=0.1, color = NA)+
xlab("Time Step")+
ylab("CV Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#Biomass, SR, Indiv Biomass on the same plot
ggplot(Biomass_Time[Biomass_Time$Species == nSpeciesMult[s] & Biomass_Time$DelPatches == nPatchDel[p] & Biomass_Time$Scale == "Local" & Biomass_Time$Rep == r,],aes(x=TimeStep,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Biomass/10, colour = "green")) + geom_line(aes(y = SR, colour = "light blue")) + geom_line(aes(y = IndivBiomass/10, colour = "pink")) +
#divide biomass and indivbiomass by 100 if using
scale_x_log10()+
#geom_ribbon(aes(ymin=Mean_SR-SD_SR,ymax=Mean_SR+SD_SR),width=0.1, color = NA)+
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
Biomass_TimeSummd <- summarise(group_by(Biomass_Time,Dispersal,Patch_remove,Scale, Species, DelPatches, TimeStep), Mean_SR = mean(SR, na.rm=T), SD_SR = sd(SR, na.rm = T), Mean_Biomass = mean(Biomass, na.rm=T), SD_Biomass = sd(Biomass, na.rm = T), Mean_IndivBiomass = mean(IndivBiomass, na.rm=T), SD_IndivBiomass = sd(IndivBiomass, na.rm = T), Mean_CVTime = mean(CVTime, na.rm=T), SD_CVTime = sd(CVTime, na.rm = T))
ggplot(Biomass_TimeSummd[Biomass_TimeSummd$Species == nSpeciesMult[s] & Biomass_TimeSummd$DelPatches == nPatchDel[p] & Biomass_TimeSummd$Scale == "Local",],aes(x=TimeStep,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_Biomass/10, colour = "Biomass/100")) + geom_line(aes(y = Mean_SR, colour = "Species Richness")) + geom_line(aes(y = Mean_IndivBiomass/10, colour = "Average Biomass per Species /100")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Mean_SR-SD_SR,ymax=Mean_SR+SD_SR),width=0.1, fill = "blue", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=(Mean_Biomass/10)-(SD_Biomass/10),ymax=(Mean_Biomass/10)+(SD_Biomass/10)),width=0.1, fill = "green", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=(Mean_IndivBiomass/10)-(SD_IndivBiomass/10),ymax=(Mean_IndivBiomass/10)+(SD_IndivBiomass/10)),width=0.1, fill = "red", alpha = 0.4, color = NA)+
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(Biomass_TimeSummd[Biomass_TimeSummd$Species == nSpeciesMult[s] & Biomass_TimeSummd$DelPatches == nPatchDel[p],],aes(x=TimeStep,y=Mean_CVTime,color=Scale,group=interaction(Scale, Patch_remove, Dispersal),fill=Scale, alpha = 0.1))+
#geom_point()+
geom_line()+
scale_x_log10()+
geom_ribbon(aes(ymin=Mean_CVTime-SD_CVTime,ymax=Mean_CVTime+SD_CVTime),width=0.1, color = NA)+
xlab("Time Step")+
ylab("CV Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime)+ #makes sense because now the first 20 points are just the CV of the last period before patch deletion
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#binning the biomass data because otherwise just see massively fluctuating sine waves
BiomassTime_Bin <- Biomass_Time %>%
group_by(Dispersal, Patch_remove, Scale, Species, DelPatches, Rep) %>%
mutate(TimeStepRound = ceiling(TimeStep/20)) %>%
group_by(TimeStepRound, Dispersal,Patch_remove, Scale, Species, DelPatches, Rep)%>%
summarize(Mean_Biomass = mean(Biomass, na.rm = T), Mean_IndivBiomass = mean(IndivBiomass, na.rm = T), Mean_SR = mean(SR, na.rm = T), Mean_CVTime = mean(CVTime, na.rm = T)) %>%
group_by(Dispersal, Patch_remove, Species, DelPatches, Scale, TimeStepRound) %>%
summarize(SD_Biomass = sd(Mean_Biomass, na.rm = T), Mean_BiomassFinal = mean(Mean_Biomass, na.rm = T), Mean_IndivBiomassFinal = mean(Mean_IndivBiomass, na.rm = T), SD_IndivBiomass = sd(Mean_IndivBiomass, na.rm = T), Mean_SRFinal = mean(Mean_SR, na.rm = T), SD_SR = sd(Mean_SR, na.rm = T), Mean_CVTimeFinal = mean(Mean_CVTime, na.rm=T), SD_CVTime = sd(Mean_CVTime, na.rm=T))
ggplot(BiomassTime_Bin[BiomassTime_Bin$Species == nSpeciesMult[s] & BiomassTime_Bin$DelPatches == nPatchDel[p] & BiomassTime_Bin$Scale == "Local",],aes(x=TimeStepRound,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_BiomassFinal/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_SRFinal, colour = "Species Richness")) + geom_line(aes(y = Mean_IndivBiomassFinal/10, colour = "avg Biomass per Species /10")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
#geom_ribbon(aes(ymin=Mean_SR-SD_SR,ymax=Mean_SR+SD_SR),width=0.1, color = NA)+
xlab("Time Step")+
#ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime/20)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(BiomassTime_Bin[BiomassTime_Bin$Species == nSpeciesMult[s] & BiomassTime_Bin$DelPatches == nPatchDel[p] & BiomassTime_Bin$Scale == "Local",],aes(x=TimeStepRound,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_BiomassFinal/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_SRFinal, colour = "Species Richness")) + geom_line(aes(y = Mean_IndivBiomassFinal/10, colour = "Biomass per Species /10")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Mean_SRFinal-SD_SR,ymax=Mean_SRFinal+SD_SR),width=0.1, color = NA, alpha = 0.1, fill = "blue")+
geom_ribbon(aes(ymin=(Mean_BiomassFinal/10)-(SD_Biomass/10),ymax=(Mean_BiomassFinal/10)+(SD_Biomass/10)),width=0.1,alpha = 0.1, fill = "green", color = NA)+
geom_ribbon(aes(ymin=(Mean_IndivBiomassFinal/10)-(SD_Biomass/10),ymax=(Mean_IndivBiomassFinal/10)+(SD_Biomass/10)),width=0.1,alpha = 0.1, fill = "red", color = NA)+
xlab("Time Step")+
#ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime/20)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
ggplot(BiomassTime_Bin[BiomassTime_Bin$Species == nSpeciesMult[s] & BiomassTime_Bin$DelPatches == nPatchDel[p],],aes(x=TimeStepRound,y=Mean_CVTimeFinal,color=Scale,group=interaction(Scale, Patch_remove, Dispersal),fill=Scale, alpha = 0.1))+
#geom_point()+
geom_line()+
scale_x_log10()+
geom_ribbon(aes(ymin=Mean_CVTimeFinal-SD_CVTime,ymax=Mean_CVTimeFinal+SD_CVTime),width=0.1, color = NA)+
xlab("Time Step")+
ylab("CV Biomass (Binned)")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted"))+
geom_vline(x=predel_collecttime/20)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
Biomass_TimeSummd2 <- summarise(group_by(Biomass_Time,Dispersal,Patch_remove,Scale, Species, DelPatches, TimeStep), Mean_SR = mean(SR, na.rm=T), Upper_SR = quantile(SR, probs=.975, na.rm = T, names = F),Lower_SR = quantile(SR, probs=.025, na.rm = T, names = F), Mean_Biomass = mean(Biomass, na.rm=T), Upper_Biomass = quantile(Biomass, probs=.975, na.rm = T, names = F),Lower_Biomass = quantile(Biomass, probs=.025, na.rm = T, names = F), Mean_IndivBiomass = mean(IndivBiomass, na.rm=T), Upper_IndivBiomass = quantile(IndivBiomass, probs=.975, na.rm = T, names = F),Lower_IndivBiomass = quantile(IndivBiomass, probs=.025, na.rm = T, names = F), Mean_CVTime = mean(CVTime, na.rm=T), Upper_CVTime = quantile(CVTime, probs=.975, na.rm = T, names = F),Lower_CVTime = quantile(CVTime, probs=.025, na.rm = T, names = F))
#CV, Biomass, SR on one graph
ggplot(Biomass_TimeSummd2[Biomass_TimeSummd2$Species == nSpeciesMult[s] & Biomass_TimeSummd2$DelPatches == nPatchDel[p] & Biomass_TimeSummd2$Scale == "Local",],aes(x=TimeStep,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_Biomass/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_SR, colour = "Species Richness")) + geom_line(aes(y = Mean_CVTime, colour = "CV Biomass")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Lower_SR,ymax=Upper_SR),width=0.1, fill = "blue", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_Biomass/10,ymax=Upper_Biomass/10),width=0.1, fill = "red", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_CVTime,ymax=Upper_CVTime/10),width=0.1, fill = "green", alpha = 0.4, color = NA)+
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted", "Local scale"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#CV, Biomass, Indiv Biomass, SR on one graph
ggplot(Biomass_TimeSummd2[Biomass_TimeSummd2$Species == nSpeciesMult[s] & Biomass_TimeSummd2$DelPatches == nPatchDel[p] & Biomass_TimeSummd2$Scale == "Local",],aes(x=TimeStep,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_Biomass/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_IndivBiomass/10, colour = "Indiv Biomass/10")) + geom_line(aes(y = Mean_SR, colour = "Species Richness")) + geom_line(aes(y = Mean_CVTime, colour = "CV Biomass")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Lower_SR,ymax=Upper_SR),width=0.1, fill = "purple", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_Biomass/10,ymax=Upper_Biomass/10),width=0.1, fill = "red", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_IndivBiomass/10,ymax=Upper_IndivBiomass/10),width=0.1, fill = "cyan", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_CVTime,ymax=Upper_CVTime/10),width=0.1, fill = "green", alpha = 0.4, color = NA)+
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted", "Local scale"))+
geom_vline(x=predel_collecttime)+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#copied from above
Biomass_TimeSummd2 <- summarise(group_by(Biomass_Time,Dispersal,Patch_remove,Scale, Species, DelPatches, TimeStep), Mean_SR = mean(SR, na.rm=T), Upper_SR = quantile(SR, probs=.975, na.rm = T, names = F),Lower_SR = quantile(SR, probs=.025, na.rm = T, names = F), Mean_Biomass = mean(Biomass, na.rm=T), Upper_Biomass = quantile(Biomass, probs=.975, na.rm = T, names = F),Lower_Biomass = quantile(Biomass, probs=.025, na.rm = T, names = F), Mean_IndivBiomass = mean(IndivBiomass, na.rm=T), Upper_IndivBiomass = quantile(IndivBiomass, probs=.975, na.rm = T, names = F),Lower_IndivBiomass = quantile(IndivBiomass, probs=.025, na.rm = T, names = F), Mean_CVTime = mean(CVTime, na.rm=T), Upper_CVTime = quantile(CVTime, probs=.975, na.rm = T, names = F),Lower_CVTime = quantile(CVTime, probs=.025, na.rm = T, names = F))
EDdata_avgchange <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches), Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLoss=quantile(SRLoss, probs = 0.025, na.rm=T, names = F), Highest_SRLoss=quantile(SRLoss, probs = 0.975, na.rm=T, names = F),
Mean_SRLossNoDel = mean(SRLossNoDel, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_BiomassChange = mean(BiomassChange, na.rm=T), SD_BiomassChange = sd(BiomassChange, na.rm = T), Lowest_BiomassChange=quantile(BiomassChange, probs = 0.025, na.rm=T, names = F), Highest_BiomassChange=quantile(BiomassChange, probs = 0.975, na.rm=T, names = F),
Mean_BmassLossNoDel = mean(BmassLossNoDel, na.rm=T), SD_BmassLossNoDel = sd(BmassLossNoDel, na.rm = T), Lowest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_IndivBmassLossNoDel = mean(IndivBmassLossNoDel, na.rm=T), SD_IndivBmassLossNoDel = sd(IndivBmassLossNoDel, na.rm = T), Lowest_IndivBmassLossNoDel=quantile(IndivBmassLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_IndivBmassLossNoDel=quantile(IndivBmassLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_CVChange = mean(CVChange, na.rm=T), SD_CVChange = sd(CVChange, na.rm = T), Lowest_CVChange=quantile(CVChange, probs = 0.025, na.rm=T, names = F), Highest_CVChange=quantile(CVChange, probs = 0.975, na.rm=T, names = F), Mean_CVChangeNoDel = mean(CVChangeNoDel, na.rm=T), SD_CVChangeNoDel = sd(CVChangeNoDel, na.rm = T), Lowest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.025, na.rm=T, names = F), Highest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.975, na.rm=T, names = F))
#^ should probably change this in the for loops below to EDdata_avgall...EDdata_avgchange is sort of a redundant data frame in the context of EDdata_avgall
Biomass_TimeSummd3 <- Biomass_TimeSummd2
for(i in 1:length(dispV)){
for(j in 1:length(removeV)){
for(s in 1:length(nSpeciesMult)){
for(p in 1:length(nPatchDel)){
Biomass_TimeSummd3$Mean_BmassLossNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"] <-
Biomass_TimeSummd3$Mean_Biomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_BmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
Biomass_TimeSummd3$Mean_IndivBmassLossNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"] <-
Biomass_TimeSummd3$Mean_IndivBiomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_IndivBmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
Biomass_TimeSummd3$Mean_SRLossNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"] <- Biomass_TimeSummd3$Mean_SR[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_SRLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
Biomass_TimeSummd3$Mean_CVChangeNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"] <-
Biomass_TimeSummd3$Mean_CVTime[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_CVChangeNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
Biomass_TimeSummd3$Mean_BmassLossNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"] <-
Biomass_TimeSummd3$Mean_Biomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"][predel_collecttime] - EDdata_avgchange$Mean_BmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"]
Biomass_TimeSummd3$Mean_IndivBmassLossNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"] <-
Biomass_TimeSummd3$Mean_IndivBiomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"][predel_collecttime] - EDdata_avgchange$Mean_IndivBmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"]
Biomass_TimeSummd3$Mean_SRLossNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"] <- Biomass_TimeSummd3$Mean_SR[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"][predel_collecttime] - EDdata_avgchange$Mean_SRLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"]
Biomass_TimeSummd3$Mean_CVChangeNoDel[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"] <-
Biomass_TimeSummd3$Mean_CVTime[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"][predel_collecttime] - EDdata_avgchange$Mean_CVChangeNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"]
}}}}
#CV, Biomass, Indiv Biomass, SR on one graph <- Goal: plot this with the no-del variants as lines in the same colours
ggplot(Biomass_TimeSummd3[Biomass_TimeSummd3$Species == nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches == nPatchDel[p] & Biomass_TimeSummd3$Scale == "Local",],aes(x=TimeStep,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_Biomass/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_IndivBiomass/10, colour = "Indiv Biomass/10")) + geom_line(aes(y = Mean_SR, colour = "Species Richness")) + geom_line(aes(y = Mean_CVTime, colour = "CV Biomass")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Lower_SR,ymax=Upper_SR),width=0.1, fill = "purple", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_Biomass/10,ymax=Upper_Biomass/10),width=0.1, fill = "red", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_IndivBiomass/10,ymax=Upper_IndivBiomass/10),width=0.1, fill = "cyan", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_CVTime,ymax=Upper_CVTime),width=0.1, fill = "green", alpha = 0.4, color = NA)+ #read Upper_CVTime/10 until 6.23.2016
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted", "Local scale"))+
geom_vline(x=predel_collecttime)+
geom_hline(aes(yintercept=Mean_BmassLossNoDel/10), color = "red", linetype = "dashed")+
geom_hline(aes(yintercept=Mean_IndivBmassLossNoDel/10), color = "cyan", linetype = "dashed")+
geom_hline(aes(yintercept=Mean_CVChangeNoDel), color = "green", linetype = "dashed")+
geom_hline(aes(yintercept=Mean_SRLossNoDel), color = "purple", linetype = "dashed")+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#copied from above
Biomass_TimeSummd2 <- summarise(group_by(Biomass_Time,Dispersal,Patch_remove,Scale, Species, DelPatches, TimeStep), Mean_SR = mean(SR, na.rm=T), Upper_SR = quantile(SR, probs=.975, na.rm = T, names = F),Lower_SR = quantile(SR, probs=.025, na.rm = T, names = F), Mean_Biomass = mean(Biomass, na.rm=T), Upper_Biomass = quantile(Biomass, probs=.975, na.rm = T, names = F),Lower_Biomass = quantile(Biomass, probs=.025, na.rm = T, names = F), Mean_IndivBiomass = mean(IndivBiomass, na.rm=T), Upper_IndivBiomass = quantile(IndivBiomass, probs=.975, na.rm = T, names = F),Lower_IndivBiomass = quantile(IndivBiomass, probs=.025, na.rm = T, names = F), Mean_CVTime = mean(CVTime, na.rm=T), Upper_CVTime = quantile(CVTime, probs=.975, na.rm = T, names = F),Lower_CVTime = quantile(CVTime, probs=.025, na.rm = T, names = F))
EDdata_avgchange <- summarise(group_by(ED_data,Dispersal,Patch_remove,Scale, Species, DelPatches), Mean_SRLoss = mean(SRLoss, na.rm=T), SD_SRLoss = sd(SRLoss, na.rm = T), Lowest_SRLoss=quantile(SRLoss, probs = 0.025, na.rm=T, names = F), Highest_SRLoss=quantile(SRLoss, probs = 0.975, na.rm=T, names = F),
Mean_SRLossNoDel = mean(SRLossNoDel, na.rm=T), SD_SRLossNoDel = sd(SRLossNoDel, na.rm = T), Lowest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_SRLossNoDel=quantile(SRLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_BiomassChange = mean(BiomassChange, na.rm=T), SD_BiomassChange = sd(BiomassChange, na.rm = T), Lowest_BiomassChange=quantile(BiomassChange, probs = 0.025, na.rm=T, names = F), Highest_BiomassChange=quantile(BiomassChange, probs = 0.975, na.rm=T, names = F),
Mean_BmassLossNoDel = mean(BmassLossNoDel, na.rm=T), SD_BmassLossNoDel = sd(BmassLossNoDel, na.rm = T), Lowest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_BmassLossNoDel=quantile(BmassLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_IndivBmassLossNoDel = mean(IndivBmassLossNoDel, na.rm=T), SD_IndivBmassLossNoDel = sd(IndivBmassLossNoDel, na.rm = T), Lowest_IndivBmassLossNoDel=quantile(IndivBmassLossNoDel, probs = 0.025, na.rm=T, names = F), Highest_IndivBmassLossNoDel=quantile(IndivBmassLossNoDel, probs = 0.975, na.rm=T, names = F),
Mean_CVChange = mean(CVChange, na.rm=T), SD_CVChange = sd(CVChange, na.rm = T), Lowest_CVChange=quantile(CVChange, probs = 0.025, na.rm=T, names = F), Highest_CVChange=quantile(CVChange, probs = 0.975, na.rm=T, names = F), Mean_CVChangeNoDel = mean(CVChangeNoDel, na.rm=T), SD_CVChangeNoDel = sd(CVChangeNoDel, na.rm = T), Lowest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.025, na.rm=T, names = F), Highest_CVChangeNoDel=quantile(CVChangeNoDel, probs = 0.975, na.rm=T, names = F),
MeanMean_SRLossNoDel = mean(Mean_SRLossNoDel, na.rm=T),MeanMean_CVChangeNoDel = mean(Mean_CVChangeNoDel, na.rm=T), MeanMean_BmassLossNoDel = mean(Mean_BmassLossNoDel, na.rm=T),MeanMean_IndivBmassLossNoDel = mean(Mean_IndivBmassLossNoDel, na.rm=T) )
#^ should probably change this in the for loops below to EDdata_avgall...EDdata_avgchange is sort of a redundant data frame in the context of EDdata_avgall
Biomass_TimeSummd4 <- Biomass_TimeSummd2
for(i in 1:length(dispV)){
for(j in 1:length(removeV)){
for(s in 1:length(nSpeciesMult)){
for(p in 1:length(nPatchDel)){
Biomass_TimeSummd4$Mean_BmassLossNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"] <-
c(rep(mean(Biomass_TimeSummd4$Mean_Biomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_Biomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_BmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_IndivBmassLossNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"] <- c(rep(mean(Biomass_TimeSummd4$Mean_IndivBiomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_IndivBiomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_IndivBmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_SRLossNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"] <- c(rep(mean(Biomass_TimeSummd4$Mean_SR[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_SR[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_SRLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_CVChangeNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"] <-
c(rep(mean(Biomass_TimeSummd4$Mean_CVTime[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_CVTime[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Local"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_CVChangeNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_BmassLossNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"] <-
c(rep(mean(Biomass_TimeSummd4$Mean_Biomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_Biomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_BmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_IndivBmassLossNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"] <- c(rep(mean(Biomass_TimeSummd4$Mean_IndivBiomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_IndivBiomass[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_IndivBmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_SRLossNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"] <- c(rep(mean(Biomass_TimeSummd4$Mean_SR[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_SR[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_SRLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"],(length(sampleV) - predel_collecttime)))
Biomass_TimeSummd4$Mean_CVChangeNoDel[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"] <-
c(rep(mean(Biomass_TimeSummd4$Mean_CVTime[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]),predel_collecttime),rep(mean(Biomass_TimeSummd4$Mean_CVTime[Biomass_TimeSummd4$Dispersal==dispV[i] & Biomass_TimeSummd4$Patch_remove==removeV[j] & Biomass_TimeSummd4$Species==nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches==nPatchDel[p] & Biomass_TimeSummd4$Scale=="Regional"][1:predel_collecttime]) - EDdata_avgchange$MeanMean_CVChangeNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"],(length(sampleV) - predel_collecttime)))
}}}}
#CV, Biomass, Indiv Biomass, SR on one graph <- Goal: plot this with the no-del variants as lines in the same colours
ggplot(Biomass_TimeSummd4[Biomass_TimeSummd4$Species == nSpeciesMult[s] & Biomass_TimeSummd4$DelPatches == nPatchDel[p] & Biomass_TimeSummd4$Scale == "Local",],aes(x=TimeStep,group=interaction(Patch_remove, Dispersal)))+
#geom_point()+
geom_line(aes(y = Mean_Biomass/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_IndivBiomass/10, colour = "Indiv Biomass/10")) + geom_line(aes(y = Mean_SR, colour = "Species Richness")) + geom_line(aes(y = Mean_CVTime, colour = "CV Biomass")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Lower_SR,ymax=Upper_SR),width=0.1, fill = "purple", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_Biomass/10,ymax=Upper_Biomass/10),width=0.1, fill = "red", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_IndivBiomass/10,ymax=Upper_IndivBiomass/10),width=0.1, fill = "cyan", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_CVTime,ymax=Upper_CVTime),width=0.1, fill = "green", alpha = 0.4, color = NA)+ #read Upper_CVTime/10 until 6.23.2016
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", nPatchDel[p], "patches deleted", "Local scale"))+
geom_vline(x=predel_collecttime)+
geom_line(aes(y=Mean_BmassLossNoDel/10), color = "red", linetype = "dashed")+
geom_line(aes(y=Mean_IndivBmassLossNoDel/10), color = "cyan", linetype = "dashed")+
geom_line(aes(y=Mean_CVChangeNoDel), color = "green", linetype = "dashed")+
geom_line(aes(y=Mean_SRLossNoDel), color = "purple", linetype = "dashed")+
facet_grid(Dispersal~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
#another way to plot everything, used when only had data for one dispersal level...
ggplot(Biomass_TimeSummd4[Biomass_TimeSummd4$Species == nSpeciesMult[s] & Biomass_TimeSummd4$Dispersal == 5e-4 & Biomass_TimeSummd4$Scale == "Local",],aes(x=TimeStep,group=interaction(Patch_remove, DelPatches)))+
#geom_point()+
geom_line(aes(y = Mean_Biomass/10, colour = "Biomass/10")) + geom_line(aes(y = Mean_IndivBiomass/10, colour = "Indiv Biomass/10")) + geom_line(aes(y = Mean_SR, colour = "Species Richness")) + geom_line(aes(y = Mean_CVTime, colour = "CV Biomass")) +
#divide biomass and indivbiomass by 100 if 'regional'
scale_x_log10()+
geom_ribbon(aes(ymin=Lower_SR,ymax=Upper_SR),width=0.1, fill = "purple", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_Biomass/10,ymax=Upper_Biomass/10),width=0.1, fill = "red", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_IndivBiomass/10,ymax=Upper_IndivBiomass/10),width=0.1, fill = "cyan", alpha = 0.4, color = NA)+
geom_ribbon(aes(ymin=Lower_CVTime,ymax=Upper_CVTime),width=0.1, fill = "green", alpha = 0.4, color = NA)+ #read Upper_CVTime/10 until 6.23.2016
xlab("Time Step")+
ylab("Biomass")+
ggtitle(paste(nSpeciesMult[s], "Species and", 5e-4, "dispersal level", "Local scale"))+
geom_vline(x=predel_collecttime)+
geom_hline(aes(yintercept=Mean_BmassLossNoDel/10), color = "red", linetype = "dashed")+
geom_hline(aes(yintercept=Mean_IndivBmassLossNoDel/10), color = "cyan", linetype = "dashed")+
geom_hline(aes(yintercept=Mean_CVChangeNoDel), color = "green", linetype = "dashed")+
geom_hline(aes(yintercept=Mean_SRLossNoDel), color = "purple", linetype = "dashed")+
facet_grid(DelPatches~Patch_remove)+
#facet_grid(Dispersal~Patch_remove,scale="free")+
#facet_grid(Scale~Patch_remove,scale="free")+
theme_bw(base_size = 18)+ #gets rid of grey background
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) #removes grid lines
BiomassTime_Bin2 <- Biomass_Time %>%
group_by(Dispersal, Patch_remove, Scale, Species, DelPatches, Rep) %>%
mutate(TimeStepRound = ceiling(TimeStep/20)) %>%
group_by(TimeStepRound, Dispersal,Patch_remove, Scale, Species, DelPatches, Rep)%>%
summarize(Mean_Biomass = mean(Biomass, na.rm = T), Mean_IndivBiomass = mean(IndivBiomass, na.rm = T), Mean_SR = mean(SR, na.rm = T), Mean_CVTime = mean(CVTime, na.rm = T)) %>%
group_by(Dispersal, Patch_remove, Species, DelPatches, Scale, TimeStepRound) %>%
summarize(Mean_SR_Final = mean(Mean_SR, na.rm=T), Upper_SR = quantile(Mean_SR, probs=.975, na.rm = T, names = F),Lower_SR = quantile(Mean_SR, probs=.025, na.rm = T, names = F), Mean_Biomass_Final = mean(Mean_Biomass, na.rm=T), Upper_Biomass = quantile(Mean_Biomass, probs=.975, na.rm = T, names = F),Lower_Biomass = quantile(Mean_Biomass, probs=.025, na.rm = T, names = F), Mean_IndivBiomass_Final = mean(Mean_IndivBiomass, na.rm=T), Upper_IndivBiomass = quantile(Mean_IndivBiomass, probs=.975, na.rm = T, names = F),Lower_IndivBiomass = quantile(Mean_IndivBiomass, probs=.025, na.rm = T, names = F), Mean_CVTime_Final = mean(Mean_CVTime, na.rm=T), Upper_CVTime = quantile(Mean_CVTime, probs=.975, na.rm = T, names = F),Lower_CVTime = quantile(Mean_CVTime, probs=.025, na.rm = T, names = F))
for(i in 1:length(dispV)){
for(j in 1:length(removeV)){
for(s in 1:length(nSpeciesMult)){
for(p in 1:length(nPatchDel)){
BiomassTime_Bin2$Mean_BmassLossNoDel[BiomassTime_Bin2$Dispersal==dispV[i] & BiomassTime_Bin2$Patch_remove==removeV[j] & BiomassTime_Bin2$Species==nSpeciesMult[s] & BiomassTime_Bin2$DelPatches==nPatchDel[p] & BiomassTime_Bin2$Scale=="Local"] <-
Biomass_TimeSummd3$Mean_Biomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_BmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
BiomassTime_Bin2$Mean_IndivBmassLossNoDel[BiomassTime_Bin2$Dispersal==dispV[i] & BiomassTime_Bin2$Patch_remove==removeV[j] & BiomassTime_Bin2$Species==nSpeciesMult[s] & BiomassTime_Bin2$DelPatches==nPatchDel[p] & BiomassTime_Bin2$Scale=="Local"] <-
Biomass_TimeSummd3$Mean_IndivBiomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_IndivBmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
BiomassTime_Bin2$Mean_SRLossNoDel[BiomassTime_Bin2$Dispersal==dispV[i] & BiomassTime_Bin2$Patch_remove==removeV[j] & BiomassTime_Bin2$Species==nSpeciesMult[s] & BiomassTime_Bin2$DelPatches==nPatchDel[p] & BiomassTime_Bin2$Scale=="Local"] <- Biomass_TimeSummd3$Mean_SR[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_SRLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
BiomassTime_Bin2$Mean_CVChangeNoDel[BiomassTime_Bin2$Dispersal==dispV[i] & BiomassTime_Bin2$Patch_remove==removeV[j] & BiomassTime_Bin2$Species==nSpeciesMult[s] & BiomassTime_Bin2$DelPatches==nPatchDel[p] & BiomassTime_Bin2$Scale=="Local"] <-
Biomass_TimeSummd3$Mean_CVTime[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Local"][predel_collecttime] - EDdata_avgchange$Mean_CVChangeNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Local"]
BiomassTime_Bin2$Mean_BmassLossNoDel[BiomassTime_Bin2$Dispersal==dispV[i] & BiomassTime_Bin2$Patch_remove==removeV[j] & BiomassTime_Bin2$Species==nSpeciesMult[s] & BiomassTime_Bin2$DelPatches==nPatchDel[p] & BiomassTime_Bin2$Scale=="Regional"] <-
Biomass_TimeSummd3$Mean_Biomass[Biomass_TimeSummd3$Dispersal==dispV[i] & Biomass_TimeSummd3$Patch_remove==removeV[j] & Biomass_TimeSummd3$Species==nSpeciesMult[s] & Biomass_TimeSummd3$DelPatches==nPatchDel[p] & Biomass_TimeSummd3$Scale=="Regional"][predel_collecttime] - EDdata_avgchange$Mean_BmassLossNoDel[EDdata_avgchange$Dispersal==dispV[i] & EDdata_avgchange$Patch_remove==removeV[j] & EDdata_avgchange$Species==nSpeciesMult[s] & EDdata_avgchange$DelPatches==nPatchDel[p] & EDdata_avgchange$Scale=="Regional"]