Instructions

Answer the following questions and/or complete the exercises in RMarkdown. Please embed all of your code and push the final work to your repository. Your report should be organized, clean, and run free from errors. Remember, you must remove the # for any included code chunks to run.

Load the tidyverse

library("tidyverse")
library("janitor")

Data

For this assignment, we will use data from a study on vertebrate community composition and impacts from defaunation in Gabon, Africa. One thing to notice is that the data include 24 separate transects. Each transect represents a path through different forest management areas.

Reference: Koerner SE, Poulsen JR, Blanchard EJ, Okouyi J, Clark CJ. Vertebrate community composition and diversity declines along a defaunation gradient radiating from rural villages in Gabon. Journal of Applied Ecology. 2016. This paper, along with a description of the variables is included inside the data folder.

1. Load IvindoData_DryadVersion.csv and store it as a new object called gabon.

gabon <- read_csv("data/IvindoData_DryadVersion.csv")
## Rows: 24 Columns: 26
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): HuntCat, LandUse
## dbl (24): TransectID, Distance, NumHouseholds, Veg_Rich, Veg_Stems, Veg_lian...
## 
## ℹ 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.

2. Use one or more of the summary functions you have learned to get an idea of the structure of the data.

glimpse(gabon)
## Rows: 24
## Columns: 26
## $ TransectID              <dbl> 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 13, 14, 15, 16, …
## $ Distance                <dbl> 7.14, 17.31, 18.32, 20.85, 15.95, 17.47, 24.06…
## $ HuntCat                 <chr> "Moderate", "None", "None", "None", "None", "N…
## $ NumHouseholds           <dbl> 54, 54, 29, 29, 29, 29, 29, 54, 25, 73, 46, 56…
## $ LandUse                 <chr> "Park", "Park", "Park", "Logging", "Park", "Pa…
## $ Veg_Rich                <dbl> 16.67, 15.75, 16.88, 12.44, 17.13, 16.50, 14.7…
## $ Veg_Stems               <dbl> 31.20, 37.44, 32.33, 29.39, 36.00, 29.22, 31.2…
## $ Veg_liana               <dbl> 5.78, 13.25, 4.75, 9.78, 13.25, 12.88, 8.38, 8…
## $ Veg_DBH                 <dbl> 49.57, 34.59, 42.82, 36.62, 41.52, 44.07, 51.2…
## $ Veg_Canopy              <dbl> 3.78, 3.75, 3.43, 3.75, 3.88, 2.50, 4.00, 4.00…
## $ Veg_Understory          <dbl> 2.89, 3.88, 3.00, 2.75, 3.25, 3.00, 2.38, 2.71…
## $ RA_Apes                 <dbl> 1.87, 0.00, 4.49, 12.93, 0.00, 2.48, 3.78, 6.1…
## $ RA_Birds                <dbl> 52.66, 52.17, 37.44, 59.29, 52.62, 38.64, 42.6…
## $ RA_Elephant             <dbl> 0.00, 0.86, 1.33, 0.56, 1.00, 0.00, 1.11, 0.43…
## $ RA_Monkeys              <dbl> 38.59, 28.53, 41.82, 19.85, 41.34, 43.29, 46.2…
## $ RA_Rodent               <dbl> 4.22, 6.04, 1.06, 3.66, 2.52, 1.83, 3.10, 1.26…
## $ RA_Ungulate             <dbl> 2.66, 12.41, 13.86, 3.71, 2.53, 13.75, 3.10, 8…
## $ Rich_AllSpecies         <dbl> 22, 20, 22, 19, 20, 22, 23, 19, 19, 19, 21, 22…
## $ Evenness_AllSpecies     <dbl> 0.793, 0.773, 0.740, 0.681, 0.811, 0.786, 0.81…
## $ Diversity_AllSpecies    <dbl> 2.452, 2.314, 2.288, 2.006, 2.431, 2.429, 2.56…
## $ Rich_BirdSpecies        <dbl> 11, 10, 11, 8, 8, 10, 11, 11, 11, 9, 11, 11, 1…
## $ Evenness_BirdSpecies    <dbl> 0.732, 0.704, 0.688, 0.559, 0.799, 0.771, 0.80…
## $ Diversity_BirdSpecies   <dbl> 1.756, 1.620, 1.649, 1.162, 1.660, 1.775, 1.92…
## $ Rich_MammalSpecies      <dbl> 11, 10, 11, 11, 12, 12, 12, 8, 8, 10, 10, 11, …
## $ Evenness_MammalSpecies  <dbl> 0.736, 0.705, 0.650, 0.619, 0.736, 0.694, 0.77…
## $ Diversity_MammalSpecies <dbl> 1.764, 1.624, 1.558, 1.484, 1.829, 1.725, 1.92…

3. Use mutate() Change the variables HuntCat, LandUse, and TransectID to factors.

gabon <- gabon %>% 
  mutate(HuntCat = as.factor(HuntCat),
         LandUse = as.factor(LandUse),
         TransectID = as.factor(TransectID))

4. Use filter to make three new dataframes focused only on 1. national parks, 2. logging concessions, and 3. neither. Have a look at the README in the data folder so you understand the variables.

parks <- filter(gabon, LandUse == "Park")
logging <- filter(gabon, LandUse == "Logging")
neither <- filter(gabon, LandUse == "Neither")

5. How many transects are recorded for each land use type?

table(gabon$LandUse)
## 
## Logging Neither    Park 
##      13       4       7

6. For which land use type (national parks, logging, or neither) is average all species diversity the greatest?

mean(parks$Diversity_AllSpecies)
## [1] 2.425143
mean(logging$Diversity_AllSpecies)
## [1] 2.232538
mean(neither$Diversity_AllSpecies)
## [1] 2.3575

7. Use filter to find the transect that has the highest relative abundance of elephants. What land use type is this? Use arrange() to sort your results.

gabon %>% 
  select(TransectID, LandUse, RA_Elephant) %>% 
  arrange(desc(RA_Elephant))
## # A tibble: 24 × 3
##    TransectID LandUse RA_Elephant
##    <fct>      <fct>         <dbl>
##  1 18         Logging        2.3 
##  2 8          Neither        2.2 
##  3 2          Park           1.33
##  4 6          Park           1.11
##  5 4          Park           1   
##  6 13         Logging        0.99
##  7 2          Park           0.86
##  8 21         Neither        0.77
##  9 3          Logging        0.56
## 10 14         Logging        0.52
## # ℹ 14 more rows

8. Use filter to find all transects that have greater than 15 tree species or a breast height diameter between 50 and 60cm.

gabon %>% 
  select(TransectID, Veg_Rich, Veg_DBH) %>% 
  filter(Veg_Rich > 16 | (Veg_DBH >= 50 & Veg_DBH <= 60))
## # A tibble: 12 × 3
##    TransectID Veg_Rich Veg_DBH
##    <fct>         <dbl>   <dbl>
##  1 1              16.7    49.6
##  2 2              16.9    42.8
##  3 4              17.1    41.5
##  4 5              16.5    44.1
##  5 6              14.8    51.2
##  6 14             15.8    52.1
##  7 15             10.9    54.8
##  8 17             14.2    57.7
##  9 21             16.2    50.4
## 10 22             17.1    39.3
## 11 24             16.8    44.2
## 12 26             18.8    35.6
names(gabon)
##  [1] "TransectID"              "Distance"               
##  [3] "HuntCat"                 "NumHouseholds"          
##  [5] "LandUse"                 "Veg_Rich"               
##  [7] "Veg_Stems"               "Veg_liana"              
##  [9] "Veg_DBH"                 "Veg_Canopy"             
## [11] "Veg_Understory"          "RA_Apes"                
## [13] "RA_Birds"                "RA_Elephant"            
## [15] "RA_Monkeys"              "RA_Rodent"              
## [17] "RA_Ungulate"             "Rich_AllSpecies"        
## [19] "Evenness_AllSpecies"     "Diversity_AllSpecies"   
## [21] "Rich_BirdSpecies"        "Evenness_BirdSpecies"   
## [23] "Diversity_BirdSpecies"   "Rich_MammalSpecies"     
## [25] "Evenness_MammalSpecies"  "Diversity_MammalSpecies"

9.Which transects and land use types have more than 10 tree species and 10 mammal species? Use arrange() to sort by the number of tree species.

gabon %>% 
  select(TransectID, Veg_Rich, Rich_MammalSpecies, LandUse) %>% 
  filter(Veg_Rich > 10 & Rich_MammalSpecies > 10) %>% 
  arrange(desc(Veg_Rich))
## # A tibble: 9 × 4
##   TransectID Veg_Rich Rich_MammalSpecies LandUse
##   <fct>         <dbl>              <dbl> <fct>  
## 1 4              17.1                 12 Park   
## 2 22             17.1                 12 Logging
## 3 2              16.9                 11 Park   
## 4 24             16.8                 12 Park   
## 5 1              16.7                 11 Park   
## 6 5              16.5                 12 Park   
## 7 14             15.8                 11 Logging
## 8 6              14.8                 12 Park   
## 9 3              12.4                 11 Logging

10. Explore the data! Develop one question on your own that includes at least two lines of code.

Knit and Upload

Please knit your work as a .pdf or .html file and upload to Canvas. Homework is due before the start of the next lab. No late work is accepted. Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!