library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(readr)

BACKPACK VISUALIZATIONS ###

backpack <- read_csv("/Users/Shared/Tagging/Final/backpack.csv")
## Rows: 32 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
new_orders <- read_csv("/Users/Shared/Tagging/Final/new_orders.csv")
## Rows: 27 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): original_order, new_order
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(backpack,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=", ")
sep_materials <- sep_materials %>% filter(material != 'leather breast pad to hold ribbons in an \"X\"', material != 'dental floss for sewing knots')

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Backpacks, n=%s",nrow(sep_species)))+
  ylab("frequency")

#---
sep_methods <- separate_rows(sep_species,methods,sep=", ")

ggplot(data=count(sep_methods,methods), aes(x=methods,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Method Use Frequencies When Tagging Using Backpacks, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Backpacks, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                                    
##                                     Elastic cord Glue Monofilament Neoprene
##   anseriformes                                 1    0            0        0
##   cathartiformes                               0    3            0        1
##   charadriiformes...gulls.and.terns            0    0            0        1
##   falconiformes                                0    2            1        2
##   gruiformes                                   0    0            1        1
##   passeriformes                                0    0            0        0
##   phoenicopteriformes                          0    0            0        0
##   podicipediformes                             0    1            0        1
##   strigiformes                                 0    0            0        2
##   suliformes                                   0    0            0        0
##                                    
##                                     Ribbon Spectra Teflon Thread
##   anseriformes                           0       0      3      0
##   cathartiformes                         1       0      4      3
##   charadriiformes...gulls.and.terns      1       0      1      0
##   falconiformes                          0       2     14      1
##   gruiformes                             0       1      2      0
##   passeriformes                          0       0      1      0
##   phoenicopteriformes                    0       0      1      0
##   podicipediformes                       1       0      1      0
##   strigiformes                           0       2      6      0
##   suliformes                             0       0      1      0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, species==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Teflon
##   Very high             0      0
##   High                  0      0
##   Modest                1      2
##   Low Impact            0      0
##   No impact             0      1
##   Not sure              0      0
##   N/A                   0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              2    2    0   2
##   Low Impact          0    0    0   0
##   No impact           0    1    1   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "anseriformes"
##             
##              Glue Neoprene Ribbon Teflon Thread
##   Very high     0        0      0      0      0
##   High          0        0      0      0      0
##   Modest        0        0      0      1      0
##   Low Impact    1        0      1      1      1
##   No impact     1        1      0      1      1
##   Not sure      1        0      0      1      1
##   N/A           0        0      0      0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              1    1    1   1
##   Low Impact          1    1    0   1
##   No impact           0    1    1   1
##   Not sure            0    1    1   1
##   N/A                 0    0    0   0
## [1] "cathartiformes"
##             
##              Neoprene Ribbon Teflon
##   Very high         0      0      0
##   High              0      0      0
##   Modest            1      1      1
##   Low Impact        0      0      0
##   No impact         0      0      0
##   Not sure          0      0      0
##   N/A               0      0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              1    1    1   1
##   Low Impact          0    0    0   0
##   No impact           0    0    0   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "charadriiformes...gulls.and.terns"
##             
##              Glue Monofilament Neoprene Spectra Teflon Thread
##   Very high     0            0        0       0      0      0
##   High          0            0        0       0      0      0
##   Modest        1            1        1       1      2      0
##   Low Impact    0            0        1       0      7      0
##   No impact     0            0        0       1      4      0
##   Not sure      1            0        0       0      1      1
##   N/A           0            0        0       0      0      0
##             
##              Crimp Bead Glue Knot Sew Surgical
##   Very high           0    0    0   0        0
##   High                0    0    0   0        0
##   Modest              1    1    0   1        0
##   Low Impact          5    4    3   5        0
##   No impact           2    2    4   4        1
##   Not sure            0    1    1   1        0
##   N/A                 0    0    0   0        0
## [1] "falconiformes"
##             
##              Monofilament Neoprene Spectra Teflon
##   Very high             0        0       0      0
##   High                  0        0       0      0
##   Modest                0        0       0      0
##   Low Impact            0        0       0      1
##   No impact             1        1       1      1
##   Not sure              0        0       0      0
##   N/A                   0        0       0      0
##             
##              Glue Knot Sew
##   Very high     0    0   0
##   High          0    0   0
##   Modest        0    0   0
##   Low Impact    0    1   1
##   No impact     1    1   1
##   Not sure      0    0   0
##   N/A           0    0   0
## [1] "gruiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      1
##   No impact       0
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              0    0    0   0
##   Low Impact          1    1    1   1
##   No impact           0    0    0   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "passeriformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Knot Sew
##   Very high           0    0   0
##   High                0    0   0
##   Modest              0    0   0
##   Low Impact          0    0   0
##   No impact           1    1   1
##   Not sure            0    0   0
##   N/A                 0    0   0
## [1] "phoenicopteriformes"
##             
##              Glue Neoprene Ribbon Teflon
##   Very high     1        1      1      1
##   High          0        0      0      0
##   Modest        0        0      0      0
##   Low Impact    0        0      0      0
##   No impact     0        0      0      0
##   Not sure      0        0      0      0
##   N/A           0        0      0      0
##             
##              Glue Knot Sew
##   Very high     1    1   1
##   High          0    0   0
##   Modest        0    0   0
##   Low Impact    0    0   0
##   No impact     0    0   0
##   Not sure      0    0   0
##   N/A           0    0   0
## [1] "podicipediformes"
##             
##              Neoprene Spectra Teflon
##   Very high         0       0      0
##   High              0       0      0
##   Modest            1       0      1
##   Low Impact        1       1      4
##   No impact         0       1      1
##   Not sure          0       0      0
##   N/A               0       0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              0    1    1   1
##   Low Impact          3    4    4   3
##   No impact           1    1    0   1
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "strigiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Knot
##   Very high           0    0
##   High                0    0
##   Modest              0    0
##   Low Impact          0    0
##   No impact           1    1
##   Not sure            0    0
##   N/A                 0    0
## [1] "suliformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                   
##                    Elastic cord Glue Monofilament Neoprene Ribbon Spectra
##   Accipitriformes             0    5            1        5      1       4
##   Anseriformes                1    0            0        0      0       0
##   Charadriiformes             0    0            0        1      1       0
##   Gruiformes                  0    0            1        1      0       1
##   Passeriformes               0    0            0        0      0       0
##   Pelecaniformes              0    0            0        0      0       0
##   Podicipediformes            0    1            0        1      1       0
##   Suliformes                  0    0            0        0      0       0
##                   
##                    Teflon Thread
##   Accipitriformes      24      4
##   Anseriformes          3      0
##   Charadriiformes       1      0
##   Gruiformes            2      0
##   Passeriformes         1      0
##   Pelecaniformes        1      0
##   Podicipediformes      1      0
##   Suliformes            1      0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, new_order==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Teflon
##   Very high             0      0
##   High                  0      0
##   Modest                1      2
##   Low Impact            0      0
##   No impact             0      1
##   Not sure              0      0
##   N/A                   0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              2    2    0   2
##   Low Impact          0    0    0   0
##   No impact           0    1    1   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "Anseriformes"
##             
##              Glue Monofilament Neoprene Ribbon Spectra Teflon Thread
##   Very high     0            0        0      0       0      0      0
##   High          0            0        0      0       0      0      0
##   Modest        1            1        2      0       1      4      0
##   Low Impact    1            0        2      1       1     12      1
##   No impact     1            0        1      0       2      6      1
##   Not sure      2            0        0      0       0      2      2
##   N/A           0            0        0      0       0      0      0
##             
##              Crimp Bead Glue Knot Sew Surgical
##   Very high           0    0    0   0        0
##   High                0    0    0   0        0
##   Modest              2    3    2   3        0
##   Low Impact          9    9    7   9        0
##   No impact           3    4    5   6        1
##   Not sure            0    2    2   2        0
##   N/A                 0    0    0   0        0
## [1] "Accipitriformes"
##             
##              Neoprene Ribbon Teflon
##   Very high         0      0      0
##   High              0      0      0
##   Modest            1      1      1
##   Low Impact        0      0      0
##   No impact         0      0      0
##   Not sure          0      0      0
##   N/A               0      0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              1    1    1   1
##   Low Impact          0    0    0   0
##   No impact           0    0    0   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "Charadriiformes"
##             
##              Monofilament Neoprene Spectra Teflon
##   Very high             0        0       0      0
##   High                  0        0       0      0
##   Modest                0        0       0      0
##   Low Impact            0        0       0      1
##   No impact             1        1       1      1
##   Not sure              0        0       0      0
##   N/A                   0        0       0      0
##             
##              Glue Knot Sew
##   Very high     0    0   0
##   High          0    0   0
##   Modest        0    0   0
##   Low Impact    0    1   1
##   No impact     1    1   1
##   Not sure      0    0   0
##   N/A           0    0   0
## [1] "Gruiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      1
##   No impact       0
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              0    0    0   0
##   Low Impact          1    1    1   1
##   No impact           0    0    0   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "Passeriformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Knot Sew
##   Very high           0    0   0
##   High                0    0   0
##   Modest              0    0   0
##   Low Impact          0    0   0
##   No impact           1    1   1
##   Not sure            0    0   0
##   N/A                 0    0   0
## [1] "Pelecaniformes"
##             
##              Glue Neoprene Ribbon Teflon
##   Very high     1        1      1      1
##   High          0        0      0      0
##   Modest        0        0      0      0
##   Low Impact    0        0      0      0
##   No impact     0        0      0      0
##   Not sure      0        0      0      0
##   N/A           0        0      0      0
##             
##              Glue Knot Sew
##   Very high     1    1   1
##   High          0    0   0
##   Modest        0    0   0
##   Low Impact    0    0   0
##   No impact     0    0   0
##   Not sure      0    0   0
##   N/A           0    0   0
## [1] "Podicipediformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Knot
##   Very high           0    0
##   High                0    0
##   Modest              0    0
##   Low Impact          0    0
##   No impact           1    1
##   Not sure            0    0
##   N/A                 0    0
## [1] "Suliformes"
### IMPACT LEVELS OF DIFFERENT METHODS
for (methods_alt in unique(sep_methods$methods)) {
print(ggplot(data=count(filter(sep_methods,methods==methods_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_methods,methods==methods_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Backpacks, n=%s",methods_alt,nrow(filter(sep_methods,methods==methods_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Backpacks By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Backpacks By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Backpacks By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Backpacks Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Backpacks By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Backpacks By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Backpacks By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Backpacks By Material")) +
    scale_x_discrete(labels=other_vector)

# IMPACT LEVELS OF DIFFERENT EFFECTS BY METHODS
abrasion <- group_by(sep_methods,abrasion,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_methods,callous,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_methods,feather_loss,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_methods,fell_off,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_methods,strangulation,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_methods,flight_impairment,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_methods,immobilization,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_methods,other,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))

abrasion_vector <- c()
for (method_alt in sort(unique(abrasion$methods))) {
  abrasion_vector <- c(abrasion_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
callous_vector <- c()
for (method_alt in sort(unique(callous$methods))) {
  callous_vector <- c(callous_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (method_alt in sort(unique(feather_loss$methods))) {
  feather_loss_vector <- c(feather_loss_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
fell_off_vector <- c()
for (method_alt in sort(unique(fell_off$methods))) {
  fell_off_vector <- c(fell_off_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
strangulation_vector <- c()
for (method_alt in sort(unique(strangulation$methods))) {
  strangulation_vector <- c(strangulation_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (method_alt in sort(unique(flight_impairment$methods))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
immobilization_vector <- c()
for (method_alt in sort(unique(immobilization$methods))) {
  immobilization_vector <- c(immobilization_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
other_vector <- c()
for (method_alt in sort(unique(other$methods))) {
  other_vector <- c(other_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Backpacks By Method") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Backpacks By Method") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Backpacks By Method") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Backpacks Falling Off By Method")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Backpacks By Method")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Backpacks By Method")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Backpacks By Method")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Backpacks By Method")) +
    scale_x_discrete(labels=other_vector)

BREAST-BODY HARNESS VISUALIZATIONS ###

breast_body <- read_csv("/Users/Shared/Tagging/Final/breast_body.csv")
## Rows: 18 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(breast_body,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=", ")
sep_materials <- sep_materials %>% filter(material != 'steel leader passed through pvc tubing (i.e." "Dwyer 1972)', material != 'tubing provided with transmitter (PVC)')

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Breast-Body Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

#---
sep_methods <- separate_rows(sep_species,methods,sep=", ")

ggplot(data=count(sep_methods,methods), aes(x=methods,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Method Use Frequencies When Tagging Using Breast-Body Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Breast-Body Harnesses, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                                    
##                                     Dwyer 1972) Elastic cord Glue Neoprene
##   anseriformes                                1            3    2        1
##   charadriiformes...gulls.and.terns           0            0    1        1
##   passeriformes                               0            0    0        0
##   pelecaniformes                              0            0    1        1
##   strigiformes                                0            0    0        0
##   suliformes                                  0            0    0        0
##                                    
##                                     Ribbon Spectra
##   anseriformes                           2       1
##   charadriiformes...gulls.and.terns      0       0
##   passeriformes                          0       1
##   pelecaniformes                         1       0
##   strigiformes                           0       1
##   suliformes                             0       0
##                                    
##                                     steel leader passed through pvc tubing (i.e.
##   anseriformes                                                                 1
##   charadriiformes...gulls.and.terns                                            0
##   passeriformes                                                                0
##   pelecaniformes                                                               0
##   strigiformes                                                                 0
##   suliformes                                                                   0
##                                    
##                                     Teflon
##   anseriformes                           8
##   charadriiformes...gulls.and.terns      1
##   passeriformes                          1
##   pelecaniformes                         0
##   strigiformes                           1
##   suliformes                             1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, species==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Dwyer 1972) Elastic cord Glue Neoprene Ribbon Spectra
##   Very high            0            0    0        0      0       0
##   High                 0            0    0        0      0       0
##   Modest               0            1    2        1      1       0
##   Low Impact           1            2    0        0      1       0
##   No impact            0            0    0        0      0       1
##   Not sure             0            0    0        0      0       0
##   N/A                  0            0    0        0      0       0
##             
##              steel leader passed through pvc tubing (i.e. Teflon
##   Very high                                             0      0
##   High                                                  0      2
##   Modest                                                0      3
##   Low Impact                                            1      3
##   No impact                                             0      0
##   Not sure                                              0      0
##   N/A                                                   0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                1    2    3   0
##   Modest              1    3    3   0
##   Low Impact          3    4    2   2
##   No impact           1    1    1   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "anseriformes"
##             
##              Glue Neoprene Teflon
##   Very high     0        0      0
##   High          0        0      0
##   Modest        0        0      0
##   Low Impact    0        0      0
##   No impact     0        0      0
##   Not sure      1        1      1
##   N/A           0        0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     0    0
##   Not sure      1    1
##   N/A           0    0
## [1] "charadriiformes...gulls.and.terns"
##             
##              Spectra Teflon
##   Very high        0      0
##   High             0      0
##   Modest           1      1
##   Low Impact       0      0
##   No impact        0      0
##   Not sure         0      0
##   N/A              0      0
##             
##              Crimp Bead Sew
##   Very high           0   0
##   High                0   0
##   Modest              1   1
##   Low Impact          0   0
##   No impact           0   0
##   Not sure            0   0
##   N/A                 0   0
## [1] "passeriformes"
##             
##              Glue Neoprene Ribbon
##   Very high     0        0      0
##   High          0        0      0
##   Modest        0        0      0
##   Low Impact    0        0      0
##   No impact     0        0      0
##   Not sure      1        1      1
##   N/A           0        0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     0    0
##   Not sure      1    1
##   N/A           0    0
## [1] "pelecaniformes"
##             
##              Spectra Teflon
##   Very high        0      0
##   High             0      0
##   Modest           0      0
##   Low Impact       0      0
##   No impact        1      1
##   Not sure         0      0
##   N/A              0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              0    0    0   0
##   Low Impact          0    0    0   0
##   No impact           1    1    1   1
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "strigiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       0
##   Not sure        1
##   N/A             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          0    0    0
##   No impact           0    0    0
##   Not sure            1    1    1
##   N/A                 0    0    0
## [1] "suliformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                  
##                   Dwyer 1972) Elastic cord Glue Neoprene Ribbon Spectra
##   Accipitriformes           0            0    0        0      0       1
##   Anseriformes              1            3    2        1      2       1
##   Charadriiformes           0            0    1        1      0       0
##   Passeriformes             0            0    0        0      0       1
##   Pelecaniformes            0            0    1        1      1       0
##   Suliformes                0            0    0        0      0       0
##                  
##                   steel leader passed through pvc tubing (i.e. Teflon
##   Accipitriformes                                            0      1
##   Anseriformes                                               1      8
##   Charadriiformes                                            0      1
##   Passeriformes                                              0      1
##   Pelecaniformes                                             0      0
##   Suliformes                                                 0      1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, new_order==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Dwyer 1972) Elastic cord Glue Neoprene Ribbon Spectra
##   Very high            0            0    0        0      0       0
##   High                 0            0    0        0      0       0
##   Modest               0            1    2        1      1       0
##   Low Impact           1            2    0        0      1       0
##   No impact            0            0    0        0      0       1
##   Not sure             0            0    0        0      0       0
##   N/A                  0            0    0        0      0       0
##             
##              steel leader passed through pvc tubing (i.e. Teflon
##   Very high                                             0      0
##   High                                                  0      2
##   Modest                                                0      3
##   Low Impact                                            1      3
##   No impact                                             0      0
##   Not sure                                              0      0
##   N/A                                                   0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                1    2    3   0
##   Modest              1    3    3   0
##   Low Impact          3    4    2   2
##   No impact           1    1    1   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "Anseriformes"
##             
##              Glue Neoprene Teflon
##   Very high     0        0      0
##   High          0        0      0
##   Modest        0        0      0
##   Low Impact    0        0      0
##   No impact     0        0      0
##   Not sure      1        1      1
##   N/A           0        0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     0    0
##   Not sure      1    1
##   N/A           0    0
## [1] "Charadriiformes"
##             
##              Spectra Teflon
##   Very high        0      0
##   High             0      0
##   Modest           1      1
##   Low Impact       0      0
##   No impact        0      0
##   Not sure         0      0
##   N/A              0      0
##             
##              Crimp Bead Sew
##   Very high           0   0
##   High                0   0
##   Modest              1   1
##   Low Impact          0   0
##   No impact           0   0
##   Not sure            0   0
##   N/A                 0   0
## [1] "Passeriformes"
##             
##              Glue Neoprene Ribbon
##   Very high     0        0      0
##   High          0        0      0
##   Modest        0        0      0
##   Low Impact    0        0      0
##   No impact     0        0      0
##   Not sure      1        1      1
##   N/A           0        0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     0    0
##   Not sure      1    1
##   N/A           0    0
## [1] "Pelecaniformes"
##             
##              Spectra Teflon
##   Very high        0      0
##   High             0      0
##   Modest           0      0
##   Low Impact       0      0
##   No impact        1      1
##   Not sure         0      0
##   N/A              0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              0    0    0   0
##   Low Impact          0    0    0   0
##   No impact           1    1    1   1
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "Accipitriformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       0
##   Not sure        1
##   N/A             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          0    0    0
##   No impact           0    0    0
##   Not sure            1    1    1
##   N/A                 0    0    0
## [1] "Suliformes"
### IMPACT LEVELS OF DIFFERENT METHODS
for (methods_alt in unique(sep_methods$methods)) {
print(ggplot(data=count(filter(sep_methods,methods==methods_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_methods,methods==methods_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Breast-Body Harnesses, n=%s",methods_alt,nrow(filter(sep_methods,methods==methods_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Breast-Body Harnesses By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Breast-Body Harnesses By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Breast-Body Harnesses By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Breast-Body Harnesses Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Breast-Body Harnesses By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Breast-Body Harnesses By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Breast-Body Harnesses By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Breast-Body Harnesses By Material")) +
    scale_x_discrete(labels=other_vector)

# IMPACT LEVELS OF DIFFERENT EFFECTS BY METHODS
abrasion <- group_by(sep_methods,abrasion,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_methods,callous,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_methods,feather_loss,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_methods,fell_off,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_methods,strangulation,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_methods,flight_impairment,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_methods,immobilization,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_methods,other,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))

abrasion_vector <- c()
for (method_alt in sort(unique(abrasion$methods))) {
  abrasion_vector <- c(abrasion_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
callous_vector <- c()
for (method_alt in sort(unique(callous$methods))) {
  callous_vector <- c(callous_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (method_alt in sort(unique(feather_loss$methods))) {
  feather_loss_vector <- c(feather_loss_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
fell_off_vector <- c()
for (method_alt in sort(unique(fell_off$methods))) {
  fell_off_vector <- c(fell_off_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
strangulation_vector <- c()
for (method_alt in sort(unique(strangulation$methods))) {
  strangulation_vector <- c(strangulation_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (method_alt in sort(unique(flight_impairment$methods))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
immobilization_vector <- c()
for (method_alt in sort(unique(immobilization$methods))) {
  immobilization_vector <- c(immobilization_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
other_vector <- c()
for (method_alt in sort(unique(other$methods))) {
  other_vector <- c(other_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Breast-Body Harnesses By Method") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Breast-Body Harnesses By Method") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Breast-Body Harnesses By Method") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Breast-Body Harnesses Falling Off By Method")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Breast-Body Harnesses By Method")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Breast-Body Harnesses By Method")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Breast-Body Harnesses By Method")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Breast-Body Harnesses By Method")) +
    scale_x_discrete(labels=other_vector)

CHAN-PIERSMA HARNESS VISUALIZATIONS ###

chan_piersma <- read_csv("/Users/Shared/Tagging/Final/chan_piersma.csv")
## Rows: 7 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(chan_piersma,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=", ")
sep_materials <- sep_materials %>% filter(material != '4 mm diameter')

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Chan-Piersma Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

#---
sep_methods <- separate_rows(sep_species,methods,sep=", ")

ggplot(data=count(sep_methods,methods), aes(x=methods,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Method Use Frequencies When Tagging Using Chan-Piersma Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Chan-Piersma Harnesses, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                                    
##                                     Elastic cord Glue Jewelry crimps
##   caprimulgiformes                             1    0              0
##   charadriiformes...gulls.and.terns            0    1              0
##   charadriiformes...shorebirds                 0    0              0
##   ciconiiformes                                0    1              0
##   falconiformes                                0    0              0
##   passeriformes                                0    0              0
##   strigiformes                                 1    1              1
##                                    
##                                     Monofilament Neoprene soft Nylon cord
##   caprimulgiformes                             0        0               0
##   charadriiformes...gulls.and.terns            0        1               0
##   charadriiformes...shorebirds                 1        0               0
##   ciconiiformes                                0        1               1
##   falconiformes                                0        0               0
##   passeriformes                                0        0               0
##   strigiformes                                 0        0               0
##                                    
##                                     Stretch magic Teflon
##   caprimulgiformes                              1      0
##   charadriiformes...gulls.and.terns             0      1
##   charadriiformes...shorebirds                  1      0
##   ciconiiformes                                 0      0
##   falconiformes                                 0      1
##   passeriformes                                 1      0
##   strigiformes                                  1      1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, species==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Stretch magic
##   Very high             0             0
##   High                  0             0
##   Modest                0             0
##   Low Impact            1             1
##   No impact             0             0
##   Not sure              0             0
##   N/A                   0             0
##             
##              Crimp Bead
##   Very high           0
##   High                0
##   Modest              0
##   Low Impact          1
##   No impact           0
##   Not sure            0
##   N/A                 0
## [1] "caprimulgiformes"
##             
##              Glue Neoprene Teflon
##   Very high     0        0      0
##   High          0        0      0
##   Modest        0        0      0
##   Low Impact    1        1      1
##   No impact     0        0      0
##   Not sure      0        0      0
##   N/A           0        0      0
##             
##              Glue Knot Sew
##   Very high     0    0   0
##   High          0    0   0
##   Modest        0    0   0
##   Low Impact    1    1   1
##   No impact     0    0   0
##   Not sure      0    0   0
##   N/A           0    0   0
## [1] "charadriiformes...gulls.and.terns"
##             
##              Monofilament Stretch magic
##   Very high             0             0
##   High                  0             0
##   Modest                1             1
##   Low Impact            0             0
##   No impact             0             0
##   Not sure              0             0
##   N/A                   0             0
##             
##              Knot
##   Very high     0
##   High          0
##   Modest        1
##   Low Impact    0
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "charadriiformes...shorebirds"
##             
##              Glue Neoprene soft Nylon cord
##   Very high     0        0               0
##   High          0        0               0
##   Modest        0        0               0
##   Low Impact    1        1               1
##   No impact     0        0               0
##   Not sure      0        0               0
##   N/A           0        0               0
##             
##              Glue Heat shrink tube
##   Very high     0                0
##   High          0                0
##   Modest        0                0
##   Low Impact    1                1
##   No impact     0                0
##   Not sure      0                0
##   N/A           0                0
## [1] "ciconiiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     1    1
##   Not sure      0    0
##   N/A           0    0
## [1] "falconiformes"
##             
##              Stretch magic
##   Very high              0
##   High                   0
##   Modest                 0
##   Low Impact             0
##   No impact              1
##   Not sure               0
##   N/A                    0
##             
##              Crimp Bead Knot
##   Very high           0    0
##   High                0    0
##   Modest              0    0
##   Low Impact          0    0
##   No impact           1    1
##   Not sure            0    0
##   N/A                 0    0
## [1] "passeriformes"
##             
##              Elastic cord Glue Jewelry crimps Stretch magic Teflon
##   Very high             0    0              0             0      0
##   High                  0    0              0             0      0
##   Modest                0    0              0             0      0
##   Low Impact            1    1              1             1      1
##   No impact             0    0              0             0      0
##   Not sure              0    0              0             0      0
##   N/A                   0    0              0             0      0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "strigiformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                   
##                    Elastic cord Glue Jewelry crimps Monofilament Neoprene
##   Accipitriformes             1    1              1            0        0
##   Caprimulgiformes            1    0              0            0        0
##   Charadriiformes             0    1              0            1        1
##   Passeriformes               0    0              0            0        0
##   Pelecaniformes              0    1              0            0        1
##                   
##                    soft Nylon cord Stretch magic Teflon
##   Accipitriformes                0             1      2
##   Caprimulgiformes               0             1      0
##   Charadriiformes                0             1      1
##   Passeriformes                  0             1      0
##   Pelecaniformes                 1             0      0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, new_order==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Stretch magic
##   Very high             0             0
##   High                  0             0
##   Modest                0             0
##   Low Impact            1             1
##   No impact             0             0
##   Not sure              0             0
##   N/A                   0             0
##             
##              Crimp Bead
##   Very high           0
##   High                0
##   Modest              0
##   Low Impact          1
##   No impact           0
##   Not sure            0
##   N/A                 0
## [1] "Caprimulgiformes"
##             
##              Glue Monofilament Neoprene Stretch magic Teflon
##   Very high     0            0        0             0      0
##   High          0            0        0             0      0
##   Modest        0            1        0             1      0
##   Low Impact    1            0        1             0      1
##   No impact     0            0        0             0      0
##   Not sure      0            0        0             0      0
##   N/A           0            0        0             0      0
##             
##              Glue Knot Sew
##   Very high     0    0   0
##   High          0    0   0
##   Modest        0    1   0
##   Low Impact    1    1   1
##   No impact     0    0   0
##   Not sure      0    0   0
##   N/A           0    0   0
## [1] "Charadriiformes"
##             
##              Glue Neoprene soft Nylon cord
##   Very high     0        0               0
##   High          0        0               0
##   Modest        0        0               0
##   Low Impact    1        1               1
##   No impact     0        0               0
##   Not sure      0        0               0
##   N/A           0        0               0
##             
##              Glue Heat shrink tube
##   Very high     0                0
##   High          0                0
##   Modest        0                0
##   Low Impact    1                1
##   No impact     0                0
##   Not sure      0                0
##   N/A           0                0
## [1] "Pelecaniformes"
##             
##              Elastic cord Glue Jewelry crimps Stretch magic Teflon
##   Very high             0    0              0             0      0
##   High                  0    0              0             0      0
##   Modest                0    0              0             0      0
##   Low Impact            1    1              1             1      1
##   No impact             0    0              0             0      1
##   Not sure              0    0              0             0      0
##   N/A                   0    0              0             0      0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    1    1
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "Accipitriformes"
##             
##              Stretch magic
##   Very high              0
##   High                   0
##   Modest                 0
##   Low Impact             0
##   No impact              1
##   Not sure               0
##   N/A                    0
##             
##              Crimp Bead Knot
##   Very high           0    0
##   High                0    0
##   Modest              0    0
##   Low Impact          0    0
##   No impact           1    1
##   Not sure            0    0
##   N/A                 0    0
## [1] "Passeriformes"
### IMPACT LEVELS OF DIFFERENT METHODS
for (methods_alt in unique(sep_methods$methods)) {
print(ggplot(data=count(filter(sep_methods,methods==methods_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_methods,methods==methods_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Chan-Piersma Harnesses, n=%s",methods_alt,nrow(filter(sep_methods,methods==methods_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Chan-Piersma Harnesses By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Chan-Piersma Harnesses By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Chan-Piersma Harnesses By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Chan-Piersma Harnesses Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Chan-Piersma Harnesses By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Chan-Piersma Harnesses By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Chan-Piersma Harnesses By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Chan-Piersma Harnesses By Material")) +
    scale_x_discrete(labels=other_vector)

# IMPACT LEVELS OF DIFFERENT EFFECTS BY METHODS
abrasion <- group_by(sep_methods,abrasion,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_methods,callous,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_methods,feather_loss,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_methods,fell_off,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_methods,strangulation,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_methods,flight_impairment,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_methods,immobilization,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_methods,other,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))

abrasion_vector <- c()
for (method_alt in sort(unique(abrasion$methods))) {
  abrasion_vector <- c(abrasion_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
callous_vector <- c()
for (method_alt in sort(unique(callous$methods))) {
  callous_vector <- c(callous_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (method_alt in sort(unique(feather_loss$methods))) {
  feather_loss_vector <- c(feather_loss_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
fell_off_vector <- c()
for (method_alt in sort(unique(fell_off$methods))) {
  fell_off_vector <- c(fell_off_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
strangulation_vector <- c()
for (method_alt in sort(unique(strangulation$methods))) {
  strangulation_vector <- c(strangulation_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (method_alt in sort(unique(flight_impairment$methods))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
immobilization_vector <- c()
for (method_alt in sort(unique(immobilization$methods))) {
  immobilization_vector <- c(immobilization_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
other_vector <- c()
for (method_alt in sort(unique(other$methods))) {
  other_vector <- c(other_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Chan-Piersma Harnesses By Method") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Chan-Piersma Harnesses By Method") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Chan-Piersma Harnesses By Method") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Chan-Piersma Harnesses Falling Off By Method")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Chan-Piersma Harnesses By Method")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Chan-Piersma Harnesses By Method")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Chan-Piersma Harnesses By Method")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Chan-Piersma Harnesses By Method")) +
    scale_x_discrete(labels=other_vector)

FULL-BODY HARNESS VISUALIZATIONS ###

fullbody <- read_csv("/Users/Shared/Tagging/Final/fullbody.csv")
## Rows: 14 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(fullbody,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=", ")
unique(sep_materials$material)
## [1] "Elastic cord"                                        
## [2] "Teflon"                                              
## [3] "3 layers: rope through rubber tube and teflon around"
## [4] "Spectra"                                             
## [5] "Monofilament"                                        
## [6] "Stretch magic"                                       
## [7] "surgical material"
sep_materials <- sep_materials %>% filter(material != '3 layers: rope through rubber tube and teflon around')

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Full Body Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

#---
sep_methods <- separate_rows(sep_species,methods,sep=", ")

ggplot(data=count(sep_methods,methods), aes(x=methods,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Method Use Frequencies When Tagging Using Full Body Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Full Body Harnesses, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                                    
##                                     Elastic cord Monofilament Spectra
##   anseriformes                                 1            0       0
##   charadriiformes...gulls.and.terns            0            0       0
##   charadriiformes...shorebirds                 0            1       1
##   falconiformes                                0            0       0
##   gruiformes                                   0            0       0
##   pelecaniformes                               0            0       0
##                                    
##                                     Stretch magic surgical material Teflon
##   anseriformes                                  0                 0      1
##   charadriiformes...gulls.and.terns             0                 0      4
##   charadriiformes...shorebirds                  1                 1      0
##   falconiformes                                 0                 0      4
##   gruiformes                                    0                 0      1
##   pelecaniformes                                0                 0      1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, species==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Teflon
##   Very high             0      0
##   High                  0      0
##   Modest                1      1
##   Low Impact            0      0
##   No impact             0      0
##   Not sure              0      0
##   N/A                   0      0
##             
##              Crimp Bead Glue
##   Very high           0    0
##   High                0    0
##   Modest              1    2
##   Low Impact          0    0
##   No impact           0    0
##   Not sure            0    0
##   N/A                 0    0
## [1] "anseriformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          1
##   Low Impact      1
##   No impact       2
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot Sew Surgical
##   Very high           0    0    0   0        0
##   High                0    0    0   0        0
##   Modest              0    1    1   1        0
##   Low Impact          0    1    0   1        0
##   No impact           1    2    1   2        1
##   Not sure            0    0    0   0        0
##   N/A                 0    0    0   0        0
## [1] "charadriiformes...gulls.and.terns"
##             
##              Monofilament Spectra Stretch magic surgical material
##   Very high             0       0             0                 0
##   High                  0       0             0                 0
##   Modest                0       0             0                 0
##   Low Impact            0       0             1                 1
##   No impact             0       0             0                 0
##   Not sure              0       0             0                 0
##   N/A                   0       0             0                 0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          0    1    1
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "charadriiformes...shorebirds"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      3
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              aluminium clip glued to tag Crimp Bead Glue Knot Sew Surgical
##   Very high                            0          0    0    0   0        0
##   High                                 0          0    0    0   0        0
##   Modest                               0          0    0    0   0        0
##   Low Impact                           1          1    2    3   1        0
##   No impact                            0          1    0    1   1        1
##   Not sure                             0          0    0    0   0        0
##   N/A                                  0          0    0    0   0        0
## [1] "falconiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      1
##   No impact       0
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "gruiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      1
##   No impact       0
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "pelecaniformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                  
##                   Elastic cord Monofilament Spectra Stretch magic
##   Accipitriformes            0            0       0             0
##   Anseriformes               1            0       0             0
##   Charadriiformes            0            1       1             1
##   Gruiformes                 0            0       0             0
##   Pelecaniformes             0            0       0             0
##                  
##                   surgical material Teflon
##   Accipitriformes                 0      4
##   Anseriformes                    0      1
##   Charadriiformes                 1      4
##   Gruiformes                      0      1
##   Pelecaniformes                  0      1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, new_order==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Teflon
##   Very high             0      0
##   High                  0      0
##   Modest                1      1
##   Low Impact            0      0
##   No impact             0      0
##   Not sure              0      0
##   N/A                   0      0
##             
##              Crimp Bead Glue
##   Very high           0    0
##   High                0    0
##   Modest              1    2
##   Low Impact          0    0
##   No impact           0    0
##   Not sure            0    0
##   N/A                 0    0
## [1] "Anseriformes"
##             
##              Monofilament Spectra Stretch magic surgical material Teflon
##   Very high             0       0             0                 0      0
##   High                  0       0             0                 0      0
##   Modest                0       0             0                 0      1
##   Low Impact            0       0             1                 1      1
##   No impact             0       0             0                 0      2
##   Not sure              0       0             0                 0      0
##   N/A                   0       0             0                 0      0
##             
##              Crimp Bead Glue Knot Sew Surgical
##   Very high           0    0    0   0        0
##   High                0    0    0   0        0
##   Modest              0    1    1   1        0
##   Low Impact          0    2    1   1        0
##   No impact           1    2    1   2        1
##   Not sure            0    0    0   0        0
##   N/A                 0    0    0   0        0
## [1] "Charadriiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      3
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              aluminium clip glued to tag Crimp Bead Glue Knot Sew Surgical
##   Very high                            0          0    0    0   0        0
##   High                                 0          0    0    0   0        0
##   Modest                               0          0    0    0   0        0
##   Low Impact                           1          1    2    3   1        0
##   No impact                            0          1    0    1   1        1
##   Not sure                             0          0    0    0   0        0
##   N/A                                  0          0    0    0   0        0
## [1] "Accipitriformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      1
##   No impact       0
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "Gruiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      1
##   No impact       0
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "Pelecaniformes"
### IMPACT LEVELS OF DIFFERENT METHODS
for (methods_alt in unique(sep_methods$methods)) {
print(ggplot(data=count(filter(sep_methods,methods==methods_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_methods,methods==methods_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Full Body Harnesses, n=%s",methods_alt,nrow(filter(sep_methods,methods==methods_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Full Body Harnesses By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Full Body Harnesses By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Full Body Harnesses By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Full Body Harnesses Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Full Body Harnesses By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Full Body Harnesses By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Full Body Harnesses By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Full Body Harnesses By Material")) +
    scale_x_discrete(labels=other_vector)

# IMPACT LEVELS OF DIFFERENT EFFECTS BY METHODS
abrasion <- group_by(sep_methods,abrasion,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_methods,callous,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_methods,feather_loss,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_methods,fell_off,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_methods,strangulation,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_methods,flight_impairment,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_methods,immobilization,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_methods,other,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))

abrasion_vector <- c()
for (method_alt in sort(unique(abrasion$methods))) {
  abrasion_vector <- c(abrasion_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
callous_vector <- c()
for (method_alt in sort(unique(callous$methods))) {
  callous_vector <- c(callous_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (method_alt in sort(unique(feather_loss$methods))) {
  feather_loss_vector <- c(feather_loss_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
fell_off_vector <- c()
for (method_alt in sort(unique(fell_off$methods))) {
  fell_off_vector <- c(fell_off_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
strangulation_vector <- c()
for (method_alt in sort(unique(strangulation$methods))) {
  strangulation_vector <- c(strangulation_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (method_alt in sort(unique(flight_impairment$methods))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
immobilization_vector <- c()
for (method_alt in sort(unique(immobilization$methods))) {
  immobilization_vector <- c(immobilization_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
other_vector <- c()
for (method_alt in sort(unique(other$methods))) {
  other_vector <- c(other_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Full Body Harnesses By Method") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Full Body Harnesses By Method") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Full Body Harnesses By Method") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Full Body Harnesses Falling Off By Method")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Full Body Harnesses By Method")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Full Body Harnesses By Method")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Full Body Harnesses By Method")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Full Body Harnesses By Method")) +
    scale_x_discrete(labels=other_vector)

LEG-LOOP HARNESS ###

legloop <- read_csv("/Users/Shared/Tagging/Final/legloop.csv")
## Rows: 83 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(legloop,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=", ")
unique(sep_materials$material)
##  [1] "Teflon"                                          
##  [2] "Elastic cord"                                    
##  [3] "Thread"                                          
##  [4] "Silicone"                                        
##  [5] "Spectra"                                         
##  [6] "Stretch magic"                                   
##  [7] "Neoprene"                                        
##  [8] "Glue"                                            
##  [9] "surgical tubing over stretch magic"              
## [10] "Ribbon"                                          
## [11] "Monofilament"                                    
## [12] "catheter tubing"                                 
## [13] "not sure what the scrub jay harness material was"
## [14] "some sort of thread"
sep_materials <- sep_materials %>% filter(material != 'surgical tubing over stretch magic', material != 'not sure what the scrub jay harness material was',material != 'some sort of thread')

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Leg-Loop Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

#---
sep_methods <- separate_rows(sep_species,methods,sep=", ")
unique(sep_methods$methods)
## [1] "Crimp Bead"                               
## [2] "Knot"                                     
## [3] "Sew"                                      
## [4] "Glue"                                     
## [5] "Solder"                                   
## [6] "Crimp used was an aluminium fishing crimp"
## [7] NA                                         
## [8] "melting stretch magic together"
sep_methods <- sep_methods %>% filter(methods != 'Crimp used was an aluminium fishing crimp', methods != 'melting stretch magic together')

ggplot(data=count(sep_methods,methods), aes(x=methods,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Method Use Frequencies When Tagging Using Leg-Loop Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Leg-Loop Harnesses, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                                    
##                                     catheter tubing Elastic cord Glue
##   cathartiformes                                  0            1    0
##   charadriiformes...gulls.and.terns               0            1    1
##   charadriiformes...shorebirds                    0            3    3
##   coraciiformes                                   0            1    0
##   falconiformes                                   0            2    0
##   galliformes                                     0            0    0
##   gruiformes                                      0            1    0
##   passeriformes                                   2           18    1
##   piciformes                                      0            3    1
##   strigiformes                                    0            0    0
##   suliformes                                      0            0    0
##                                    
##                                     Monofilament Neoprene Ribbon Silicone
##   cathartiformes                               0        0      0        1
##   charadriiformes...gulls.and.terns            0        1      0        1
##   charadriiformes...shorebirds                 0        1      1        3
##   coraciiformes                                1        0      0        0
##   falconiformes                                0        0      0        0
##   galliformes                                  0        0      0        0
##   gruiformes                                   0        0      0        0
##   passeriformes                                1        0      1        0
##   piciformes                                   1        1      0        0
##   strigiformes                                 0        1      0        0
##   suliformes                                   0        0      0        0
##                                    
##                                     Spectra Stretch magic Teflon Thread
##   cathartiformes                          0             0      3      1
##   charadriiformes...gulls.and.terns       2             2      7      0
##   charadriiformes...shorebirds            1            11     10      0
##   coraciiformes                           0             0      0      0
##   falconiformes                           2             0      7      0
##   galliformes                             0             0      3      0
##   gruiformes                              0             2      0      0
##   passeriformes                           0            27      2      4
##   piciformes                              0             0      2      1
##   strigiformes                            0             0      1      0
##   suliformes                              0             0      1      0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, species==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Silicone Teflon Thread
##   Very high             0        0      0      0
##   High                  0        0      0      0
##   Modest                0        0      0      0
##   Low Impact            1        0      2      1
##   No impact             0        1      1      0
##   Not sure              0        0      0      0
##   N/A                   0        0      0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              0    0    0   0
##   Low Impact          2    0    1   1
##   No impact           1    1    1   0
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "cathartiformes"
##             
##              Elastic cord Glue Neoprene Silicone Spectra Stretch magic Teflon
##   Very high             0    0        0        0       0             0      0
##   High                  0    0        0        0       0             0      0
##   Modest                0    0        0        0       1             0      1
##   Low Impact            1    1        1        1       1             2      4
##   No impact             0    0        0        0       0             0      0
##   Not sure              0    0        0        0       0             0      2
##   N/A                   0    0        0        0       0             0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              1    2    2   0
##   Low Impact          3    2    3   1
##   No impact           0    0    0   0
##   Not sure            1    2    2   0
##   N/A                 0    0    0   0
## [1] "charadriiformes...gulls.and.terns"
##             
##              Elastic cord Glue Neoprene Ribbon Silicone Spectra Stretch magic
##   Very high             0    0        0      0        0       0             0
##   High                  0    0        0      0        0       0             0
##   Modest                1    2        0      0        1       0             4
##   Low Impact            2    0        0      1        2       1             6
##   No impact             0    1        1      0        0       0             1
##   Not sure              0    0        0      0        0       0             0
##   N/A                   0    0        0      0        0       0             0
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          1
##   Low Impact      6
##   No impact       3
##   Not sure        0
##   N/A             0
##             
##              Crimp Bead Glue Knot Sew Solder
##   Very high           0    0    0   0      0
##   High                0    0    0   0      0
##   Modest              4    5    4   0      0
##   Low Impact          8    6    8   0      1
##   No impact           2    3    3   1      0
##   Not sure            0    0    0   0      0
##   N/A                 0    0    0   0      0
## [1] "charadriiformes...shorebirds"
##             
##              Elastic cord Monofilament
##   Very high             0            0
##   High                  0            0
##   Modest                0            0
##   Low Impact            1            1
##   No impact             0            0
##   Not sure              0            0
##   N/A                   0            0
## < table of extent 7 x 0 >
## [1] "coraciiformes"
##             
##              Elastic cord Spectra Teflon
##   Very high             0       0      0
##   High                  0       0      0
##   Modest                1       1      3
##   Low Impact            0       1      1
##   No impact             1       0      3
##   Not sure              0       0      0
##   N/A                   0       0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              2    1    2   1
##   Low Impact          1    1    1   1
##   No impact           1    2    1   1
##   Not sure            0    0    0   0
##   N/A                 0    0    0   0
## [1] "falconiformes"
##             
##              Teflon
##   Very high       0
##   High            1
##   Modest          0
##   Low Impact      0
##   No impact       0
##   Not sure        0
##   N/A             2
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                1    1    1
##   Modest              0    0    0
##   Low Impact          0    0    0
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 2    1    0
## [1] "galliformes"
##             
##              Elastic cord Stretch magic
##   Very high             0             0
##   High                  0             0
##   Modest                0             0
##   Low Impact            1             1
##   No impact             0             1
##   Not sure              0             0
##   N/A                   0             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    1    1
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "gruiformes"
##             
##              catheter tubing Elastic cord Glue Monofilament Ribbon
##   Very high                0            1    0            0      0
##   High                     0            0    0            0      0
##   Modest                   0            3    0            0      1
##   Low Impact               0           13    1            0      0
##   No impact                0            1    0            1      0
##   Not sure                 1            0    0            0      0
##   N/A                      1            0    0            0      0
##             
##              Stretch magic Teflon Thread
##   Very high              0      0      0
##   High                   0      0      0
##   Modest                 8      0      1
##   Low Impact            13      2      2
##   No impact              4      0      1
##   Not sure               2      0      0
##   N/A                    0      0      0
##             
##              Crimp Bead Glue Knot Sew Solder
##   Very high           0    1    1   0      0
##   High                0    0    0   0      0
##   Modest              2    6    5   0      3
##   Low Impact          3   15   12   1      4
##   No impact           3    4    5   0      1
##   Not sure            2    2    2   0      0
##   N/A                 1    0    0   0      0
## [1] "passeriformes"
##             
##              Elastic cord Glue Monofilament Neoprene Teflon Thread
##   Very high             0    0            0        0      0      0
##   High                  0    0            0        0      0      0
##   Modest                0    0            0        0      0      0
##   Low Impact            2    1            1        1      2      1
##   No impact             1    0            0        0      0      0
##   Not sure              0    0            0        0      0      0
##   N/A                   0    0            0        0      0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    3    3
##   No impact     0    1
##   Not sure      0    0
##   N/A           0    0
## [1] "piciformes"
##             
##              Neoprene Teflon
##   Very high         0      0
##   High              0      0
##   Modest            0      0
##   Low Impact        0      0
##   No impact         0      0
##   Not sure          1      1
##   N/A               0      0
##             
##              Crimp Bead
##   Very high           0
##   High                0
##   Modest              0
##   Low Impact          0
##   No impact           0
##   Not sure            1
##   N/A                 0
## [1] "strigiformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Glue
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     1
##   Not sure      0
##   N/A           0
## [1] "suliformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                  
##                   catheter tubing Elastic cord Glue Monofilament Neoprene
##   Accipitriformes               0            3    0            0        1
##   Charadriiformes               0            4    4            0        2
##   Galliformes                   0            0    0            0        0
##   Gruiformes                    0            1    0            0        0
##   Near Passerines               0            4    1            2        1
##   Passeriformes                 2           18    1            1        0
##   Suliformes                    0            0    0            0        0
##                  
##                   Ribbon Silicone Spectra Stretch magic Teflon Thread
##   Accipitriformes      0        1       2             0     11      1
##   Charadriiformes      1        4       3            13     17      0
##   Galliformes          0        0       0             0      3      0
##   Gruiformes           0        0       0             2      0      0
##   Near Passerines      0        0       0             0      2      1
##   Passeriformes        1        0       0            27      2      4
##   Suliformes           0        0       0             0      1      0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, new_order==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord Neoprene Silicone Spectra Teflon Thread
##   Very high             0        0        0       0      0      0
##   High                  0        0        0       0      0      0
##   Modest                1        0        0       1      3      0
##   Low Impact            1        0        0       1      3      1
##   No impact             1        0        1       0      4      0
##   Not sure              0        1        0       0      1      0
##   N/A                   0        0        0       0      0      0
##             
##              Crimp Bead Glue Knot Sew
##   Very high           0    0    0   0
##   High                0    0    0   0
##   Modest              2    1    2   1
##   Low Impact          3    1    2   2
##   No impact           2    3    2   1
##   Not sure            1    0    0   0
##   N/A                 0    0    0   0
## [1] "Accipitriformes"
##             
##              Elastic cord Glue Neoprene Ribbon Silicone Spectra Stretch magic
##   Very high             0    0        0      0        0       0             0
##   High                  0    0        0      0        0       0             0
##   Modest                1    2        0      0        1       1             4
##   Low Impact            3    1        1      1        3       2             8
##   No impact             0    1        1      0        0       0             1
##   Not sure              0    0        0      0        0       0             0
##   N/A                   0    0        0      0        0       0             0
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          2
##   Low Impact     10
##   No impact       3
##   Not sure        2
##   N/A             0
##             
##              Crimp Bead Glue Knot Sew Solder
##   Very high           0    0    0   0      0
##   High                0    0    0   0      0
##   Modest              5    7    6   0      0
##   Low Impact         11    8   11   1      1
##   No impact           2    3    3   1      0
##   Not sure            1    2    2   0      0
##   N/A                 0    0    0   0      0
## [1] "Charadriiformes"
##             
##              Elastic cord Glue Monofilament Neoprene Teflon Thread
##   Very high             0    0            0        0      0      0
##   High                  0    0            0        0      0      0
##   Modest                0    0            0        0      0      0
##   Low Impact            3    1            2        1      2      1
##   No impact             1    0            0        0      0      0
##   Not sure              0    0            0        0      0      0
##   N/A                   0    0            0        0      0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    3    3
##   No impact     0    1
##   Not sure      0    0
##   N/A           0    0
## [1] "Near Passerines"
##             
##              Teflon
##   Very high       0
##   High            1
##   Modest          0
##   Low Impact      0
##   No impact       0
##   Not sure        0
##   N/A             2
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                1    1    1
##   Modest              0    0    0
##   Low Impact          0    0    0
##   No impact           0    0    0
##   Not sure            0    0    0
##   N/A                 2    1    0
## [1] "Galliformes"
##             
##              Elastic cord Stretch magic
##   Very high             0             0
##   High                  0             0
##   Modest                0             0
##   Low Impact            1             1
##   No impact             0             1
##   Not sure              0             0
##   N/A                   0             0
##             
##              Crimp Bead Glue Knot
##   Very high           0    0    0
##   High                0    0    0
##   Modest              0    0    0
##   Low Impact          1    1    1
##   No impact           0    1    1
##   Not sure            0    0    0
##   N/A                 0    0    0
## [1] "Gruiformes"
##             
##              catheter tubing Elastic cord Glue Monofilament Ribbon
##   Very high                0            1    0            0      0
##   High                     0            0    0            0      0
##   Modest                   0            3    0            0      1
##   Low Impact               0           13    1            0      0
##   No impact                0            1    0            1      0
##   Not sure                 1            0    0            0      0
##   N/A                      1            0    0            0      0
##             
##              Stretch magic Teflon Thread
##   Very high              0      0      0
##   High                   0      0      0
##   Modest                 8      0      1
##   Low Impact            13      2      2
##   No impact              4      0      1
##   Not sure               2      0      0
##   N/A                    0      0      0
##             
##              Crimp Bead Glue Knot Sew Solder
##   Very high           0    1    1   0      0
##   High                0    0    0   0      0
##   Modest              2    6    5   0      3
##   Low Impact          3   15   12   1      4
##   No impact           3    4    5   0      1
##   Not sure            2    2    2   0      0
##   N/A                 1    0    0   0      0
## [1] "Passeriformes"
##             
##              Teflon
##   Very high       0
##   High            0
##   Modest          0
##   Low Impact      0
##   No impact       1
##   Not sure        0
##   N/A             0
##             
##              Glue
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     1
##   Not sure      0
##   N/A           0
## [1] "Suliformes"
### IMPACT LEVELS OF DIFFERENT METHODS
for (methods_alt in unique(sep_methods$methods)) {
print(ggplot(data=count(filter(sep_methods,methods==methods_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_methods,methods==methods_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Leg-Loop Harnesses, n=%s",methods_alt,nrow(filter(sep_methods,methods==methods_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Leg-Loop Harnesses By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Leg-Loop Harnesses By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Leg-Loop Harnesses By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Leg-Loop Harnesses Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Leg-Loop Harnesses By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Leg-Loop Harnesses By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Leg-Loop Harnesses By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Leg-Loop Harnesses By Material")) +
    scale_x_discrete(labels=other_vector)

# IMPACT LEVELS OF DIFFERENT EFFECTS BY METHODS
abrasion <- group_by(sep_methods,abrasion,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_methods,callous,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_methods,feather_loss,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_methods,fell_off,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_methods,strangulation,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_methods,flight_impairment,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_methods,immobilization,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_methods,other,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))

abrasion_vector <- c()
for (method_alt in sort(unique(abrasion$methods))) {
  abrasion_vector <- c(abrasion_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
callous_vector <- c()
for (method_alt in sort(unique(callous$methods))) {
  callous_vector <- c(callous_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (method_alt in sort(unique(feather_loss$methods))) {
  feather_loss_vector <- c(feather_loss_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
fell_off_vector <- c()
for (method_alt in sort(unique(fell_off$methods))) {
  fell_off_vector <- c(fell_off_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
strangulation_vector <- c()
for (method_alt in sort(unique(strangulation$methods))) {
  strangulation_vector <- c(strangulation_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (method_alt in sort(unique(flight_impairment$methods))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
immobilization_vector <- c()
for (method_alt in sort(unique(immobilization$methods))) {
  immobilization_vector <- c(immobilization_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
other_vector <- c()
for (method_alt in sort(unique(other$methods))) {
  other_vector <- c(other_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Leg-Loop Harnesses By Method") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Leg-Loop Harnesses By Method") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Leg-Loop Harnesses By Method") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Leg-Loop Harnesses Falling Off By Method")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Leg-Loop Harnesses By Method")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Leg-Loop Harnesses By Method")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Leg-Loop Harnesses By Method")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Leg-Loop Harnesses By Method")) +
    scale_x_discrete(labels=other_vector)

TESA-TAPE VISUALIZATIONS ###

tesatape <- read_csv("/Users/Shared/Tagging/Final/tesatape.csv")
## Rows: 46 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, location, why_testape, impact_level, abrasio...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(tesatape,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_location <- separate_rows(sep_species,location,sep=",")

ggplot(data=count(sep_location,location),aes(x=location,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Location of Tag Frequencies When Using Tesa Tape, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT LOCATIONS
for (location_alt in unique(sep_location$location)) {
print(ggplot(data=count(filter(sep_location,location==location_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_location,location==location_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using Tesa Tape On The %s While Tagging, n=%s",location_alt,nrow(filter(sep_location,location==location_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_location$species,sep_location$location)
##                                    
##                                     back keel tail
##   cathartiformes                       2    0    0
##   charadriiformes...alcids             7    1    0
##   charadriiformes...gulls.and.terns    7    0    1
##   charadriiformes...shorebirds         1    0    0
##   phaethontiformes                     1    0    1
##   sphenisciformes                      5    0    0
##   suliformes                           3    0   10
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_location$species)) {
order_data_location <- filter(sep_location, species==order_alt)
order_data_location$impact_level <- factor(order_data_location$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_location$impact_level,order_data_location$location))
print(order_alt)}
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     2
##   Not sure      0
##   N/A           0
## [1] "cathartiformes"
##             
##              back keel
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    6    1
##   No impact     1    0
##   Not sure      0    0
##   N/A           0    0
## [1] "charadriiformes...alcids"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    5    1
##   No impact     2    0
##   Not sure      0    0
##   N/A           0    0
## [1] "charadriiformes...gulls.and.terns"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    1
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "charadriiformes...shorebirds"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    1    1
##   No impact     0    0
##   Not sure      0    0
##   N/A           0    0
## [1] "phaethontiformes"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    3
##   No impact     2
##   Not sure      0
##   N/A           0
## [1] "sphenisciformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    2    7
##   No impact     1    3
##   Not sure      0    0
##   N/A           0    0
## [1] "suliformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_location$new_order,sep_location$location)
##                   
##                    back keel tail
##   Accipitriformes     2    0    0
##   Charadriiformes    15    1    1
##   Procellariformes    1    0    1
##   Sphenisciformes     5    0    0
##   Suliformes          3    0   10
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_location$new_order)) {
order_data_location <- filter(sep_location, new_order==order_alt)
order_data_location$impact_level <- factor(order_data_location$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_location$impact_level,order_data_location$location))
print(order_alt)}
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     2
##   Not sure      0
##   N/A           0
## [1] "Accipitriformes"
##             
##              back keel tail
##   Very high     0    0    0
##   High          0    0    0
##   Modest        0    0    0
##   Low Impact   12    1    1
##   No impact     3    0    0
##   Not sure      0    0    0
##   N/A           0    0    0
## [1] "Charadriiformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    1    1
##   No impact     0    0
##   Not sure      0    0
##   N/A           0    0
## [1] "Procellariformes"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    3
##   No impact     2
##   Not sure      0
##   N/A           0
## [1] "Sphenisciformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    2    7
##   No impact     1    3
##   Not sure      0    0
##   N/A           0    0
## [1] "Suliformes"
### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_location,abrasion,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_location,callous,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_location,feather_loss,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_location,fell_off,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_location,strangulation,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_location,flight_impairment,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_location,immobilization,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_location,other,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (location_alt in sort(unique(abrasion$location))) {
  abrasion_vector <- c(abrasion_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)),sep="\n"))
}
callous_vector <- c()
for (location_alt in sort(unique(callous$location))) {
  callous_vector <- c(callous_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (location_alt in sort(unique(feather_loss$location))) {
  feather_loss_vector <- c(feather_loss_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
fell_off_vector <- c()
for (location_alt in sort(unique(fell_off$location))) {
  fell_off_vector <- c(fell_off_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)),sep="\n"))
}
strangulation_vector <- c()
for (location_alt in sort(unique(strangulation$location))) {
  strangulation_vector <- c(strangulation_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (location_alt in sort(unique(flight_impairment$location))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
immobilization_vector <- c()
for (location_alt in sort(unique(immobilization$location))) {
  immobilization_vector <- c(immobilization_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
other_vector <- c()
for (location_alt in sort(unique(other$location))) {
  other_vector <- c(other_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Tesa Tape By Location") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies UsingTesa Tape By Location") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Tesa Tape By Location") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Tesa Tape Falling Off By Location")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Tesa Tape By Location")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Tesa Tape By Location")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Tesa Tape By Location")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Tesa Tape By Location")) +
    scale_x_discrete(labels=other_vector)

WING-LOOP HARNESS VISUALIZATIONS ###

wingloop <- read_csv("/Users/Shared/Tagging/Final/wingloop.csv")
## Rows: 7 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(wingloop,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=", ")

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Wing-Loop Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

#---
sep_methods <- separate_rows(sep_species,methods,sep=", ")

ggplot(data=count(sep_methods,methods), aes(x=methods,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Method Use Frequencies When Tagging Using Wing-Loop Harnesses, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Wing-Loop Harnesses, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                
##                 Elastic cord Thread
##   columbiformes            1      0
##   galliformes              2      1
##   passeriformes            1      1
##   strigiformes             1      0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, species==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord
##   Very high             0
##   High                  0
##   Modest                0
##   Low Impact            0
##   No impact             1
##   Not sure              0
##   N/A                   0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     1    1
##   Not sure      0    0
##   N/A           0    0
## [1] "columbiformes"
##             
##              Elastic cord Thread
##   Very high             0      0
##   High                  0      0
##   Modest                0      0
##   Low Impact            1      0
##   No impact             1      1
##   Not sure              0      0
##   N/A                   0      0
##             
##              Crimp Bead Glue Knot Solder
##   Very high           0    0    0      0
##   High                0    0    0      0
##   Modest              0    0    0      0
##   Low Impact          0    1    1      0
##   No impact           1    0    1      1
##   Not sure            0    0    0      0
##   N/A                 0    0    0      0
## [1] "galliformes"
##             
##              Elastic cord Thread
##   Very high             0      0
##   High                  0      0
##   Modest                0      0
##   Low Impact            1      0
##   No impact             0      1
##   Not sure              0      0
##   N/A                   0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    1    1
##   No impact     0    1
##   Not sure      0    0
##   N/A           0    0
## [1] "passeriformes"
##             
##              Elastic cord
##   Very high             0
##   High                  0
##   Modest                0
##   Low Impact            0
##   No impact             1
##   Not sure              0
##   N/A                   0
##             
##              Glue
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     1
##   Not sure      0
##   N/A           0
## [1] "strigiformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                  
##                   Elastic cord Thread
##   Accipitriformes            1      0
##   Galliformes                2      1
##   Near Passerines            1      0
##   Passeriformes              1      1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
order_data_methods <- filter(sep_methods, new_order==order_alt)
order_data_methods$impact_level <- factor(order_data_methods$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(table(order_data_methods$impact_level,order_data_methods$methods))
print(order_alt)}
##             
##              Elastic cord
##   Very high             0
##   High                  0
##   Modest                0
##   Low Impact            0
##   No impact             1
##   Not sure              0
##   N/A                   0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    0    0
##   No impact     1    1
##   Not sure      0    0
##   N/A           0    0
## [1] "Near Passerines"
##             
##              Elastic cord Thread
##   Very high             0      0
##   High                  0      0
##   Modest                0      0
##   Low Impact            1      0
##   No impact             1      1
##   Not sure              0      0
##   N/A                   0      0
##             
##              Crimp Bead Glue Knot Solder
##   Very high           0    0    0      0
##   High                0    0    0      0
##   Modest              0    0    0      0
##   Low Impact          0    1    1      0
##   No impact           1    0    1      1
##   Not sure            0    0    0      0
##   N/A                 0    0    0      0
## [1] "Galliformes"
##             
##              Elastic cord Thread
##   Very high             0      0
##   High                  0      0
##   Modest                0      0
##   Low Impact            1      0
##   No impact             0      1
##   Not sure              0      0
##   N/A                   0      0
##             
##              Glue Knot
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    1    1
##   No impact     0    1
##   Not sure      0    0
##   N/A           0    0
## [1] "Passeriformes"
##             
##              Elastic cord
##   Very high             0
##   High                  0
##   Modest                0
##   Low Impact            0
##   No impact             1
##   Not sure              0
##   N/A                   0
##             
##              Glue
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     1
##   Not sure      0
##   N/A           0
## [1] "Accipitriformes"
### IMPACT LEVELS OF DIFFERENT METHODS
for (methods_alt in unique(sep_methods$methods)) {
print(ggplot(data=count(filter(sep_methods,methods==methods_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_methods,methods==methods_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Wing-Loop Harnesses, n=%s",methods_alt,nrow(filter(sep_methods,methods==methods_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Wing-Loop Harnesses By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Wing-Loop Harnesses By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Wing-Loop Harnesses By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Wing-Loop Harnesses Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Wing-Loop Harnesses By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Wing-Loop Harnesses By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Wing-Loop Harnesses By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Wing-Loop Harnesses By Material")) +
    scale_x_discrete(labels=other_vector)

# IMPACT LEVELS OF DIFFERENT EFFECTS BY METHODS
abrasion <- group_by(sep_methods,abrasion,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_methods,callous,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_methods,feather_loss,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_methods,fell_off,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_methods,strangulation,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_methods,flight_impairment,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_methods,immobilization,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_methods,other,methods) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))

abrasion_vector <- c()
for (method_alt in sort(unique(abrasion$methods))) {
  abrasion_vector <- c(abrasion_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
callous_vector <- c()
for (method_alt in sort(unique(callous$methods))) {
  callous_vector <- c(callous_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (method_alt in sort(unique(feather_loss$methods))) {
  feather_loss_vector <- c(feather_loss_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
fell_off_vector <- c()
for (method_alt in sort(unique(fell_off$methods))) {
  fell_off_vector <- c(fell_off_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)),sep="\n"))
}
strangulation_vector <- c()
for (method_alt in sort(unique(strangulation$methods))) {
  strangulation_vector <- c(strangulation_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (method_alt in sort(unique(flight_impairment$methods))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
immobilization_vector <- c()
for (method_alt in sort(unique(immobilization$methods))) {
  immobilization_vector <- c(immobilization_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}
other_vector <- c()
for (method_alt in sort(unique(other$methods))) {
  other_vector <- c(other_vector,paste(method_alt,nrow(filter(sep_methods,methods==method_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Wing-Loop Harnesses By Method") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Wing-Loop Harnesses By Method") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Wing-Loop Harnesses By Method") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Wing-Loop Harnesses Falling Off By Method")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Wing-Loop Harnesses By Method")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Wing-Loop Harnesses By Method")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Wing-Loop Harnesses By Method")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=methods, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Wing-Loop Harnesses By Method")) +
    scale_x_discrete(labels=other_vector)

GLUE-ON VISUALIZATIONS ###

glue_on <- read_csv("/Users/Shared/Tagging/Final/glue_on.csv")
## Rows: 56 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): species, device_type, location, why_glue_on, impact_level, abrasio...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(glue_on,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_location <- separate_rows(sep_species,location,sep=",")

ggplot(data=count(sep_location,location),aes(x=location,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Location of Tag Frequencies When Using Glue, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT LOCATIONS
for (location_alt in unique(sep_location$location)) {
print(ggplot(data=count(filter(sep_location,location==location_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_location,location==location_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Glue On The %s While Tagging, n=%s",location_alt,nrow(filter(sep_location,location==location_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_location$species,sep_location$location)
##                                    
##                                     back tail
##   anseriformes                         4    0
##   apodiformes                          2    0
##   caprimulgiformes                     0    1
##   cathartiformes                       0    2
##   charadriiformes...alcids             3    0
##   charadriiformes...gulls.and.terns    4    1
##   charadriiformes...shorebirds        24    5
##   columbiformes                        1    0
##   falconiformes                        1    3
##   gruiformes                           1    0
##   passeriformes                        4    2
##   piciformes                           0    1
##   sphenisciformes                      1    0
##   strigiformes                         0    1
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_location$species)) {
order_data_location <- filter(sep_location, species==order_alt)
order_data_location$impact_level <- factor(order_data_location$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_location$impact_level,order_data_location$location))
print(order_alt)}
##             
##              back
##   Very high     0
##   High          0
##   Modest        1
##   Low Impact    3
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "anseriformes"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    1
##   No impact     1
##   Not sure      0
##   N/A           0
## [1] "apodiformes"
##             
##              tail
##   Very high     0
##   High          0
##   Modest        1
##   Low Impact    0
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "caprimulgiformes"
##             
##              tail
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     2
##   Not sure      0
##   N/A           0
## [1] "cathartiformes"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    3
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "charadriiformes...alcids"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    4    1
##   No impact     0    0
##   Not sure      0    0
##   N/A           0    0
## [1] "charadriiformes...gulls.and.terns"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        2    1
##   Low Impact   10    4
##   No impact    11    0
##   Not sure      0    0
##   N/A           1    0
## [1] "charadriiformes...shorebirds"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    1
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "columbiformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    1
##   Low Impact    0    0
##   No impact     1    2
##   Not sure      0    0
##   N/A           0    0
## [1] "falconiformes"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    1
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "gruiformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    1
##   Low Impact    0    0
##   No impact     4    1
##   Not sure      0    0
##   N/A           0    0
## [1] "passeriformes"
##             
##              tail
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    0
##   No impact     1
##   Not sure      0
##   N/A           0
## [1] "piciformes"
##             
##              back
##   Very high     0
##   High          1
##   Modest        0
##   Low Impact    0
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "sphenisciformes"
##             
##              tail
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    1
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "strigiformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_location$new_order,sep_location$location)
##                   
##                    back tail
##   Accipitriformes     1    6
##   Anseriformes        4    0
##   Caprimulgiformes    2    1
##   Charadriiformes    31    6
##   Gruiformes          1    0
##   Near Passerines     1    1
##   Passeriformes       4    2
##   Sphenisciformes     1    0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_location$new_order)) {
order_data_location <- filter(sep_location, new_order==order_alt)
order_data_location$impact_level <- factor(order_data_location$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_location$impact_level,order_data_location$location))
print(order_alt)}
##             
##              back
##   Very high     0
##   High          0
##   Modest        1
##   Low Impact    3
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "Anseriformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    1
##   Low Impact    1    0
##   No impact     1    0
##   Not sure      0    0
##   N/A           0    0
## [1] "Caprimulgiformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    1
##   Low Impact    0    1
##   No impact     1    4
##   Not sure      0    0
##   N/A           0    0
## [1] "Accipitriformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        2    1
##   Low Impact   17    5
##   No impact    11    0
##   Not sure      0    0
##   N/A           1    0
## [1] "Charadriiformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    0
##   Low Impact    1    0
##   No impact     0    1
##   Not sure      0    0
##   N/A           0    0
## [1] "Near Passerines"
##             
##              back
##   Very high     0
##   High          0
##   Modest        0
##   Low Impact    1
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "Gruiformes"
##             
##              back tail
##   Very high     0    0
##   High          0    0
##   Modest        0    1
##   Low Impact    0    0
##   No impact     4    1
##   Not sure      0    0
##   N/A           0    0
## [1] "Passeriformes"
##             
##              back
##   Very high     0
##   High          1
##   Modest        0
##   Low Impact    0
##   No impact     0
##   Not sure      0
##   N/A           0
## [1] "Sphenisciformes"
### IMPACT LEVELS OF DIFFERENT LOCATIONS BY EFFECTS

abrasion <- group_by(sep_location,abrasion,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_location,callous,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_location,feather_loss,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_location,fell_off,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_location,strangulation,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_location,flight_impairment,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_location,immobilization,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_location,other,location) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (location_alt in sort(unique(abrasion$location))) {
  abrasion_vector <- c(abrasion_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)),sep="\n"))
}
callous_vector <- c()
for (location_alt in sort(unique(callous$location))) {
  callous_vector <- c(callous_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (location_alt in sort(unique(feather_loss$location))) {
  feather_loss_vector <- c(feather_loss_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
fell_off_vector <- c()
for (location_alt in sort(unique(fell_off$location))) {
  fell_off_vector <- c(fell_off_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)),sep="\n"))
}
strangulation_vector <- c()
for (location_alt in sort(unique(strangulation$location))) {
  strangulation_vector <- c(strangulation_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (location_alt in sort(unique(flight_impairment$location))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
immobilization_vector <- c()
for (location_alt in sort(unique(immobilization$location))) {
  immobilization_vector <- c(immobilization_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}
other_vector <- c()
for (location_alt in sort(unique(other$location))) {
  other_vector <- c(other_vector,paste(location_alt,nrow(filter(sep_location,location==location_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Glue By Location") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Glue By Location") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Glue By Location") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Tag Falling Off By Location When Using Glue")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Glue By Location")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Glue By Location")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Glue By Location")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=location, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Glue By Location")) +
    scale_x_discrete(labels=other_vector)

LEG/TARSAL MOUNTS VISUALIZATIONS ###

leg_tarsal <- read_csv("/Users/Shared/Tagging/Final/leg_tarsal.csv")
## Rows: 54 Columns: 19
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): species, device_type, material, why_material, methods, why_methods...
## dbl  (1): id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_species <- separate_rows(leg_tarsal,species,sep=",")
sep_species <- merge(x=sep_species,y=new_orders,by.x="species",by.y="original_order")

sep_materials <- separate_rows(sep_species,material,sep=",")

ggplot(data=count(sep_materials,material),aes(x=material,y=(n/nrow(sep_species))))+
  geom_col()+
  ggtitle(sprintf("Material Use Frequencies When Tagging Using Leg/Tarsal Mounts, n=%s",nrow(sep_species)))+
  ylab("frequency")

### IMPACT LEVELS OF DIFFERENT MATERIALS
for (material_alt in unique(sep_materials$material)) {
print(ggplot(data=count(filter(sep_materials,material==material_alt),impact_level),aes(x=impact_level,y=n/nrow(filter(sep_materials,material==material_alt))))+
  geom_col()+
  ggtitle(sprintf("Impact Levels of Using %s While Attaching Leg/Tarsal Mounts, n=%s",material_alt,nrow(filter(sep_materials,material==material_alt))))+
  ylab("frequency")+
  xlab("impact level"))}

print("Original Orders:")
## [1] "Original Orders:"
table(sep_materials$species,sep_materials$material)
##                                    
##                                     cable glue metal plastic tape tesa tape
##   anseriformes                          0    0     0       2    0         0
##   charadriiformes...alcids              0    2     0       7    0         0
##   charadriiformes...gulls.and.terns     0    3     1      12    1         0
##   charadriiformes...shorebirds          0    1     0      11    0         0
##   gaviiformes                           0    0     1       1    0         0
##   gruiformes                            0    0     0       5    0         0
##   passeriformes                         0    0     0       2    0         0
##   phaethontiformes                      0    0     1       0    0         0
##   sphenisciformes                       2    0     0       1    1         0
##   strigiformes                          0    0     0       1    0         0
##   suliformes                            0    0     1       3    0         1
##                                    
##                                     zip-tie
##   anseriformes                            1
##   charadriiformes...alcids                3
##   charadriiformes...gulls.and.terns       3
##   charadriiformes...shorebirds            0
##   gaviiformes                             0
##   gruiformes                              0
##   passeriformes                           0
##   phaethontiformes                        0
##   sphenisciformes                         0
##   strigiformes                            0
##   suliformes                              0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$species)) {
order_data_materials <- filter(sep_materials, species==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(order_alt)}
##             
##              plastic zip-tie
##   Very high        0       0
##   High             0       0
##   Modest           0       0
##   Low Impact       1       1
##   No impact        1       0
##   Not sure         0       0
##   N/A              0       0
## [1] "anseriformes"
##             
##              glue plastic zip-tie
##   Very high     0       0       0
##   High          0       0       0
##   Modest        0       0       0
##   Low Impact    2       7       3
##   No impact     0       0       0
##   Not sure      0       0       0
##   N/A           0       0       0
## [1] "charadriiformes...alcids"
##             
##              glue metal plastic tape zip-tie
##   Very high     0     0       0    0       0
##   High          0     0       0    0       0
##   Modest        0     0       1    0       0
##   Low Impact    0     1       7    0       1
##   No impact     3     0       4    1       2
##   Not sure      0     0       0    0       0
##   N/A           0     0       0    0       0
## [1] "charadriiformes...gulls.and.terns"
##             
##              glue plastic
##   Very high     0       0
##   High          0       0
##   Modest        0       4
##   Low Impact    1       5
##   No impact     0       2
##   Not sure      0       0
##   N/A           0       0
## [1] "charadriiformes...shorebirds"
##             
##              metal plastic
##   Very high      0       0
##   High           0       0
##   Modest         0       0
##   Low Impact     1       0
##   No impact      0       1
##   Not sure       0       0
##   N/A            0       0
## [1] "gaviiformes"
##             
##              plastic
##   Very high        0
##   High             0
##   Modest           2
##   Low Impact       2
##   No impact        1
##   Not sure         0
##   N/A              0
## [1] "gruiformes"
##             
##              plastic
##   Very high        0
##   High             0
##   Modest           0
##   Low Impact       1
##   No impact        1
##   Not sure         0
##   N/A              0
## [1] "passeriformes"
##             
##              metal
##   Very high      0
##   High           0
##   Modest         0
##   Low Impact     0
##   No impact      1
##   Not sure       0
##   N/A            0
## [1] "phaethontiformes"
##             
##              cable plastic tape
##   Very high      0       0    0
##   High           0       0    0
##   Modest         1       1    1
##   Low Impact     1       0    0
##   No impact      0       0    0
##   Not sure       0       0    0
##   N/A            0       0    0
## [1] "sphenisciformes"
##             
##              plastic
##   Very high        0
##   High             0
##   Modest           0
##   Low Impact       0
##   No impact        1
##   Not sure         0
##   N/A              0
## [1] "strigiformes"
##             
##              metal plastic tesa tape
##   Very high      0       0         0
##   High           0       0         0
##   Modest         0       0         0
##   Low Impact     0       2         0
##   No impact      1       1         1
##   Not sure       0       0         0
##   N/A            0       0         0
## [1] "suliformes"
print("New Orders:")
## [1] "New Orders:"
table(sep_materials$new_order,sep_materials$material)
##                   
##                    cable glue metal plastic tape tesa tape zip-tie
##   Accipitriformes      0    0     0       1    0         0       0
##   Anseriformes         0    0     0       2    0         0       1
##   Charadriiformes      0    6     1      30    1         0       6
##   Gaviiformes          0    0     1       1    0         0       0
##   Gruiformes           0    0     0       5    0         0       0
##   Passeriformes        0    0     0       2    0         0       0
##   Procellariformes     0    0     1       0    0         0       0
##   Sphenisciformes      2    0     0       1    1         0       0
##   Suliformes           0    0     1       3    0         1       0
impact_levels <- c("Very High", "High", "Modest", "Low Impact", "No Impact", "Not Sure", "N/A")
for (order_alt in unique(sep_materials$new_order)) {
order_data_materials <- filter(sep_materials, new_order==order_alt)
order_data_materials$impact_level <- factor(order_data_materials$impact_level, order = TRUE, levels =c("Very high", "High", "Modest", "Low Impact", "No impact", "Not sure", "N/A"))
print(table(order_data_materials$impact_level,order_data_materials$material))
print(order_alt)}
##             
##              plastic zip-tie
##   Very high        0       0
##   High             0       0
##   Modest           0       0
##   Low Impact       1       1
##   No impact        1       0
##   Not sure         0       0
##   N/A              0       0
## [1] "Anseriformes"
##             
##              glue metal plastic tape zip-tie
##   Very high     0     0       0    0       0
##   High          0     0       0    0       0
##   Modest        0     0       5    0       0
##   Low Impact    3     1      19    0       4
##   No impact     3     0       6    1       2
##   Not sure      0     0       0    0       0
##   N/A           0     0       0    0       0
## [1] "Charadriiformes"
##             
##              metal plastic
##   Very high      0       0
##   High           0       0
##   Modest         0       0
##   Low Impact     1       0
##   No impact      0       1
##   Not sure       0       0
##   N/A            0       0
## [1] "Gaviiformes"
##             
##              plastic
##   Very high        0
##   High             0
##   Modest           2
##   Low Impact       2
##   No impact        1
##   Not sure         0
##   N/A              0
## [1] "Gruiformes"
##             
##              plastic
##   Very high        0
##   High             0
##   Modest           0
##   Low Impact       1
##   No impact        1
##   Not sure         0
##   N/A              0
## [1] "Passeriformes"
##             
##              metal
##   Very high      0
##   High           0
##   Modest         0
##   Low Impact     0
##   No impact      1
##   Not sure       0
##   N/A            0
## [1] "Procellariformes"
##             
##              cable plastic tape
##   Very high      0       0    0
##   High           0       0    0
##   Modest         1       1    1
##   Low Impact     1       0    0
##   No impact      0       0    0
##   Not sure       0       0    0
##   N/A            0       0    0
## [1] "Sphenisciformes"
##             
##              plastic
##   Very high        0
##   High             0
##   Modest           0
##   Low Impact       0
##   No impact        1
##   Not sure         0
##   N/A              0
## [1] "Accipitriformes"
##             
##              metal plastic tesa tape
##   Very high      0       0         0
##   High           0       0         0
##   Modest         0       0         0
##   Low Impact     0       2         0
##   No impact      1       1         1
##   Not sure       0       0         0
##   N/A            0       0         0
## [1] "Suliformes"
### IMPACT LEVELS OF DIFFERENT MATERIALS BY EFFECTS

abrasion <- group_by(sep_materials,abrasion,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'abrasion'. You can override using the
## `.groups` argument.
callous <- group_by(sep_materials,callous,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'callous'. You can override using the
## `.groups` argument.
feather_loss <- group_by(sep_materials,feather_loss,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'feather_loss'. You can override using the
## `.groups` argument.
fell_off <- group_by(sep_materials,fell_off,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'fell_off'. You can override using the
## `.groups` argument.
strangulation <- group_by(sep_materials,strangulation,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'strangulation'. You can override using the
## `.groups` argument.
flight_impairment <- group_by(sep_materials,flight_impairment,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'flight_impairment'. You can override using
## the `.groups` argument.
immobilization <- group_by(sep_materials,immobilization,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'immobilization'. You can override using
## the `.groups` argument.
other <- group_by(sep_materials,other,material) %>%
  summarise(n=n())
## `summarise()` has grouped output by 'other'. You can override using the
## `.groups` argument.
# Orders the effect frequencies
abrasion$abrasion <- factor(abrasion$abrasion, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
callous$callous <- factor(callous$callous, levels=c('Often (41-80%)','Rare (<10%)','Never','NA','N/A','Unknown','Not sure'))
feather_loss$feather_loss <- factor(feather_loss$feather_loss, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
fell_off$fell_off <- factor(fell_off$fell_off, levels=c('Often (41-80%)','Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
strangulation$strangulation <- factor(strangulation$strangulation, levels=c('Rare (<10%)','Never','NA','Unknown','Not sure'))
flight_impairment$flight_impairment <- factor(flight_impairment$flight_impairment, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
immobilization$immobilization <- factor(immobilization$immobilization, levels=c('Sometimes (10-40%)','Rare (<10%)','Never','NA','Unknown','Not sure'))
other$other <- factor(other$other, levels=c('Always (>80%)','Rare (<10%)','Never','NA','N/A','Not sure'))

###
# Creates labels for abrasion plot along with sample sizes
abrasion_vector <- c()
for (material_alt in sort(unique(abrasion$material))) {
  abrasion_vector <- c(abrasion_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
callous_vector <- c()
for (material_alt in sort(unique(callous$material))) {
  callous_vector <- c(callous_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
feather_loss_vector <- c()
for (material_alt in sort(unique(feather_loss$material))) {
  feather_loss_vector <- c(feather_loss_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
fell_off_vector <- c()
for (material_alt in sort(unique(fell_off$material))) {
  fell_off_vector <- c(fell_off_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)),sep="\n"))
}
strangulation_vector <- c()
for (material_alt in sort(unique(strangulation$material))) {
  strangulation_vector <- c(strangulation_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
flight_impairment_vector <- c()
for (material_alt in sort(unique(flight_impairment$material))) {
  flight_impairment_vector <- c(flight_impairment_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
immobilization_vector <- c()
for (material_alt in sort(unique(immobilization$material))) {
  immobilization_vector <- c(immobilization_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}
other_vector <- c()
for (material_alt in sort(unique(other$material))) {
  other_vector <- c(other_vector,paste(material_alt,nrow(filter(sep_materials,material==material_alt)), sep="\n"))
}

ggplot(data=abrasion, aes(fill=abrasion, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Abrasian Frequencies Using Leg/Tarsal Mounts By Material") +
    scale_x_discrete(labels=abrasion_vector)

ggplot(data=callous, aes(fill=callous, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Callous Frequencies Using Leg/Tarsal Mounts By Material") +
    scale_x_discrete(labels=callous_vector)

ggplot(data=feather_loss, aes(fill=feather_loss, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle("Feather Loss Frequencies Using Leg/Tarsal Mounts By Material") +
    scale_x_discrete(labels=feather_loss_vector)

ggplot(data=fell_off, aes(fill=fell_off, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Frequencies Of Leg/Tarsal Mounts Falling Off By Material")) +
    scale_x_discrete(labels=fell_off_vector)

ggplot(data=strangulation, aes(fill=strangulation, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Strangulation Frequencies Using Leg/Tarsal Mounts By Material")) +
    scale_x_discrete(labels=strangulation_vector)

ggplot(data=flight_impairment, aes(fill=flight_impairment, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Flight Impairment Frequencies Using Leg/Tarsal Mounts By Material")) +
    scale_x_discrete(labels=flight_impairment_vector)

ggplot(data=immobilization, aes(fill=immobilization, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Immobilization Frequencies Using Leg/Tarsal Mounts By Material")) +
    scale_x_discrete(labels=immobilization_vector)

ggplot(data=other, aes(fill=other, x=material, y=n)) + 
    geom_bar(position="fill", stat="identity") +
    ggtitle(sprintf("Other Frequencies Using Leg/Tarsal Mounts By Material")) +
    scale_x_discrete(labels=other_vector)