Encounter Report Code

updated 3/18/2019 by Lindsay Carlson lgcarlson@aggiemail.usu.edu

Instructions: You will need to install the packages above for this document to work. This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. To run one code chunk at a time, press the green arrow on the right hand side. Chunks must be run in order. To run everything above the current chunk, press the down arrow with the green bar underneath.

If you save this markdown file in the same folder as the dataset, it will automatically read in the data without setting a working directory.

osencounter<-read.csv("osborne_encounterrecords.csv",header=T)
#head(osencounter)
#str(osencounter)
osencounter<-as.data.frame(osencounter)

Summary Statistics

Create a table of number of encountered birds by year. These correspond to “years” not “hunting seasons.”

nbyyear<-osencounter %>%
  group_by(enc_year) %>%
  summarise(n=n())
nbyyear
## # A tibble: 6 x 2
##   enc_year     n
##      <int> <int>
## 1     2014     3
## 2     2015    30
## 3     2016    93
## 4     2017   206
## 5     2018   379
## 6     2019   103

Create a table of number of encountered birds by species

#this command is creating a tibble (table) called nbyspecies from data from "osencounter"
#it is grouping the data by species, then using summarize to count the n (number) of cases in each group
#finally, it arranges them in descending order
nbyspecies<-osencounter %>%
  group_by(species) %>%
  summarise(n=n()) %>%
  arrange(desc(n))

nbyspecies
## # A tibble: 8 x 2
##   species     n
##   <fct>   <int>
## 1 MALL      716
## 2 AGWT       36
## 3 WODU       36
## 4 GADW       20
## 5 RNDU        3
## 6 AMCO        1
## 7 NOPI        1
## 8 NSHO        1

As of 3/36/19, 88% of the recoveries were mallards.

Create a table of number of encountered birds by location.

nbylocation<-osencounter %>%
  group_by(band_location) %>%
  summarise(n=n()) %>%
  arrange(desc(n))

nbylocation
## # A tibble: 8 x 2
##   band_location     n
##   <fct>         <int>
## 1 NGLORY          300
## 2 CARMICAL        180
## 3 SIL_CAMP        110
## 4 WHITEOAKS       105
## 5 MAX_BB           67
## 6 7DEVILS          30
## 7 DDF              13
## 8 FISHPOND          9

Create a table of number of encountered birds by state.

nbystate<-osencounter %>%
  group_by(enc_state) %>%
  summarise(n=n()) 

nbystate
## # A tibble: 30 x 2
##    enc_state     n
##    <fct>     <int>
##  1 AL            1
##  2 ALB           5
##  3 AR          307
##  4 CA            1
##  5 GA            2
##  6 IA           12
##  7 IL           33
##  8 IN            4
##  9 KS           10
## 10 KY           16
## # ... with 20 more rows

Create a table of number of encountered birds by month

nbymonth<-osencounter %>%
  group_by(enc_mo) %>%
  summarise(n=n()) 

nbymonth
## # A tibble: 10 x 2
##    enc_mo     n
##     <int> <int>
##  1      1   309
##  2      2     9
##  3      3     2
##  4      4     5
##  5      5     1
##  6      8     6
##  7      9    24
##  8     10   102
##  9     11   143
## 10     12   213

Note that these plots are not calling on the original dataset, they are calling on the tibble created above.

Distance from banding location

Calculate distance from banding location to encounter location.

## # A tibble: 10 x 5
##    enc_mo mean_distkm     n    sd    se
##     <int>       <dbl> <int> <dbl> <dbl>
##  1      1       212.    309 197.   11.2
##  2      2       159.      9 170.   56.7
##  3      3        42.3     2  37.5  26.5
##  4      4      2315.      5 249.  111. 
##  5      5      1162.      1 NaN   NaN  
##  6      8      1965.      6 428.  175. 
##  7      9      1811.     24 612.  125. 
##  8     10      1789.    102 530.   52.5
##  9     11       541.    143 495.   41.4
## 10     12       326.    213 333.   22.8

Create summary tables

Create a table containing annual encounter totals by banding location. Here, we are grouping by two variables. It will group by the first listed variable first (location) in this case.

yearxbandlocation<-osencounter %>%
  group_by(band_location,enc_year) %>%
  summarise(n=n(),mean_distkm = mean(enc_distkm),sd = sd(enc_distkm),se = sd(enc_distkm)/sqrt(n)) 
yearxbandlocation
## # A tibble: 31 x 6
## # Groups:   band_location [?]
##    band_location enc_year     n mean_distkm    sd    se
##    <fct>            <int> <int>       <dbl> <dbl> <dbl>
##  1 7DEVILS           2015     4      1067.  1160. 580. 
##  2 7DEVILS           2016     9       620.   785. 262. 
##  3 7DEVILS           2017     7       785.   594. 225. 
##  4 7DEVILS           2018     9       449.   721. 240. 
##  5 7DEVILS           2019     1        61.7  NaN  NaN  
##  6 CARMICAL          2016    16       625.   722. 180. 
##  7 CARMICAL          2017    71       659.   758.  89.9
##  8 CARMICAL          2018    78       505.   650.  73.6
##  9 CARMICAL          2019    15       199.   165.  42.7
## 10 DDF               2017     5       380.   661. 295. 
## # ... with 21 more rows
#write.csv(yearxbandlocation, file = "yearxbandlocation.csv")

Create a table containing annual encounter totals by species.

yearxspecies<-osencounter %>%
  group_by(species,enc_year) %>%
  summarise(n=n()) 
yearxspecies
## # A tibble: 23 x 3
## # Groups:   species [?]
##    species enc_year     n
##    <fct>      <int> <int>
##  1 AGWT        2016     6
##  2 AGWT        2017    13
##  3 AGWT        2018    14
##  4 AGWT        2019     3
##  5 AMCO        2017     1
##  6 GADW        2016     4
##  7 GADW        2017     5
##  8 GADW        2018    10
##  9 GADW        2019     1
## 10 MALL        2014     3
## # ... with 13 more rows
#write.csv(yearxspecies, file = "yearxspecies.csv")

Create a table containing state totals by species.

statexspecies<-osencounter %>%
  group_by(enc_state,species) %>%
  summarise(n=n()) 
statexspecies
## # A tibble: 62 x 3
## # Groups:   enc_state [?]
##    enc_state species     n
##    <fct>     <fct>   <int>
##  1 AL        MALL        1
##  2 ALB       AGWT        1
##  3 ALB       MALL        4
##  4 AR        AGWT       16
##  5 AR        GADW       11
##  6 AR        MALL      271
##  7 AR        RNDU        1
##  8 AR        WODU        8
##  9 CA        AGWT        1
## 10 GA        MALL        2
## # ... with 52 more rows
#write.csv(statexspecies, file = "statexspecies.csv")

Instagram plots

Create a histogram of the number of years banded before being encountered.

Create a histogram of the distance between the banding location and the encounter location.

Create a histogram of the month of harvest.

Note, the correct month names need to be fixed in Adobe, but you can’t do a hist with a cat variable on x.

Animated Maps

Create an animated map where encounter locations are shown by date (since 2015).

## Source : http://tile.stamen.com/terrain-lines/4/2/5.png
## Source : http://tile.stamen.com/terrain-lines/4/3/5.png
## Source : http://tile.stamen.com/terrain-lines/4/4/5.png
## Source : http://tile.stamen.com/terrain-lines/4/2/6.png
## Source : http://tile.stamen.com/terrain-lines/4/3/6.png
## Source : http://tile.stamen.com/terrain-lines/4/4/6.png

Create an animated map where encounter locations are shown by month of the hunting season.

##           0 1.September   2.October  3.November  4.December   5.January 
##          23          24         102         143         213         309
## nframes and fps adjusted to match transition

Create a density map for each “hunting season” as opposed to each year. This is for mallards only

## 2014-2015 2015-2016 2016-2017 2017-2018 2018-2019 
##         4        48        98       330       311

Animate the mallard density map by monthly density.

## Source : http://tile.stamen.com/terrain-lines/4/2/4.png
## Source : http://tile.stamen.com/terrain-lines/4/3/4.png
## Source : http://tile.stamen.com/terrain-lines/4/4/4.png
## nframes and fps adjusted to match transition