library(readxl) #allows you to read in excel files
library(data.table) #for data organizing
library(tidyverse) #for this script, uses for dplyr and ggplot2
library(lubridate) #Deals with date formats
library(dplyr) #for data organizing
library(openxlsx) #read, write, and edits xlsx files
n2023 <- read_excel("C:/Users/rfriendly/Desktop/kgun/data/kgun_NOPI_2023.xlsx") #read in nopi file
## New names:
## • `` -> `...13`
n2023 <- n2023[-13] #delete column 13
a2023 <- read_excel("C:/Users/rfriendly/Desktop/kgun/data/kgun_AGWT_2023.xlsx") #read in agwt file
m2023 <- read_excel("C:/Users/rfriendly/Desktop/kgun/data/kgun_MALL_2023.xlsx") #read in mall file
all_species <- rbind(n2023,m2023,a2023) #combines data
summary(all_species)
## PREFIX SUFFIX BANDER SPECIES
## Min. :1144 Min. :12032 Length:485 Length:485
## 1st Qu.:1226 1st Qu.:74520 Class :character Class :character
## Median :1226 Median :74641 Mode :character Mode :character
## Mean :1264 Mean :71813
## 3rd Qu.:1226 3rd Qu.:74762
## Max. :2227 Max. :74883
## SEX HOWSEX AGE
## Length:485 Length:485 Length:485
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## DATE START TIME
## Min. :2023-08-02 00:00:00.00 Min. :1899-12-31 09:25:00.00
## 1st Qu.:2023-08-11 00:00:00.00 1st Qu.:1899-12-31 09:48:00.00
## Median :2023-08-14 00:00:00.00 Median :1899-12-31 10:19:00.00
## Mean :2023-08-13 09:00:22.26 Mean :1899-12-31 13:00:19.67
## 3rd Qu.:2023-08-17 00:00:00.00 3rd Qu.:1899-12-31 18:48:00.00
## Max. :2023-08-22 00:00:00.00 Max. :1899-12-31 20:36:00.00
## END TIME TRAP_ID NOTES
## Min. :1899-12-31 09:36:00.00 Length:485 Length:485
## 1st Qu.:1899-12-31 10:21:00.00 Class :character Class :character
## Median :1899-12-31 10:53:00.00 Mode :character Mode :character
## Mean :1899-12-31 13:31:58.03
## 3rd Qu.:1899-12-31 19:04:00.00
## Max. :1899-12-31 21:36:00.00
This is just practice to learn. We are going to summarize the data to get simple statistics for Northern Pintail, Mallard, and American green-winged teals.You can see some information from the imported data above. First, I am going to clean up the data before starting, these codes will not show.
table_sas <- all_species %>% count(SPECIES, AGE, SEX) #count by species and age and sex
table_sas
## # A tibble: 11 × 4
## SPECIES AGE SEX n
## <fct> <fct> <fct> <int>
## 1 AGWT AHY M 4
## 2 AGWT HY F 2
## 3 MALL AHY M 13
## 4 MALL HY F 3
## 5 MALL HY M 3
## 6 NOPI AHY F 136
## 7 NOPI AHY M 98
## 8 NOPI HY F 109
## 9 NOPI HY M 110
## 10 NOPI L F 5
## 11 NOPI L M 2
species_number <- all_species %>% count(SPECIES) #count by species
species_number
## # A tibble: 3 × 2
## SPECIES n
## <fct> <int>
## 1 AGWT 6
## 2 MALL 19
## 3 NOPI 460
trap_sp <- all_species %>% count(TRAP_ID, SPECIES) #count by trap location and species
trap_sp
## # A tibble: 8 × 3
## TRAP_ID SPECIES n
## <fct> <fct> <int>
## 1 N1 AGWT 1
## 2 N1 MALL 12
## 3 N1 NOPI 148
## 4 N2 MALL 7
## 5 N2 NOPI 223
## 6 N3 AGWT 5
## 7 N3 NOPI 68
## 8 NOPI2 NOPI 21
trap <- all_species %>% count(TRAP_ID) #count by trap location
trap
## # A tibble: 4 × 2
## TRAP_ID n
## <fct> <int>
## 1 N1 161
## 2 N2 230
## 3 N3 73
## 4 NOPI2 21
bird_table <- data.frame(Trap = c('N1','N2','N3','NOPI2'),
AGWT = c('1','0','5','0'),
NOPI = c('148','223','68','21'),
MALL = c('12','7','0','0'),
Total = c('161','230','73','21'))
bird_table
## Trap AGWT NOPI MALL Total
## 1 N1 1 148 12 161
## 2 N2 0 223 7 230
## 3 N3 5 68 0 73
## 4 NOPI2 0 21 0 21
bird_age_table <- data.frame(Age = c('L','HY','AHY'),
AGWT = c('0','2','4'),
NOPI = c('7','219','234'),
MALL = c('0','6','13'))
bird_age_table
## Age AGWT NOPI MALL
## 1 L 0 7 0
## 2 HY 2 219 6
## 3 AHY 4 234 13
library(ggplot2)
nopi_years <- read_excel("C:/Users/rfriendly/Desktop/kgun/data/nopi_numbers_2023.xlsx") #read in nopi file
mall_years <- read_excel("C:/Users/rfriendly/Desktop/kgun/data/mall_numbers_2023.xlsx") #read in mall file
agwt_years <- read_excel("C:/Users/rfriendly/Desktop/kgun/data/agwt_numbers_2023.xlsx") #read in agwt file
nopi_graph
mall_graph
agwt_graph