Engaged Learning: Part 3

New Hypothesis: Female birds are less likely to visit nests located in high-noise zones.

Original Figure 1: Barplot

install.packages("ggplot2") #install ggplot
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
library(ggplot2) #ensure ggplot installed
install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ lubridate 1.9.5     ✔ tibble    3.3.1
## ✔ purrr     1.2.2     ✔ tidyr     1.3.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Bluebird_Data <- read.csv("Bluebird_Data.csv") #loading in eastern bluebird dataset

fem_visits <- Bluebird_Data %>% #split up data
  filter(BIRDSEX == "F")#filter by females only

ggplot(fem_visits, aes(x= NS_GP2, y= IN, fill= NS_GP2)) + #create plot w fem visits across noise groups
  stat_summary(fun= sum, geom= "col", color= "black", linewidth=0.3, width= 0.7)+ #make geom_col, values are the sum of 'IN' variable per noise group
  labs(
    x= "Noise Treatments", #name x axis
    y= "Total Female Nest Visits", #name y axis
    title= "Total Female Nest Visits Across Noise Treatments" #set title
  )+
  theme_bw()+ #b&w theme
  theme(legend.position= "none", #remove legend (not necessary) 
        axis.text= element_text(color= "black")) #make axis labels black/easier to read

Original Figure 2: Scatterplot with Error Bars

ggplot(fem_visits, aes(x= NS_GP2, y= IN))+ #plot noise category + times females entered nest
  geom_point(position= position_jitter(width= 0.2), size=3, alpha= 0.6, aes(color=NS_GP2))+ #add points with jitter for overlap, lower opacity, color by noise category
  stat_summary(fun.data= mean_se, geom= "errorbar", width= 0.2)+ #create error bar 
  labs(
    x = "Noise Treatments", #name x axis
    y= "Frequency of Females Entering Nests", #name y axis
    title = "Mean Female Nest Attendance Across Noise Treatments" #add title
  )+
  theme_bw()+ #b&w theme
  theme(legend.position="none", #remove legend (not necessary) 
        axis.text= element_text(color= "black")) #make axis labels black/easier to read