knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4
)
library(alohakez)
library(tidyverse)

take a look at data first

convert data types

head(cce_seabird)
tail(cce_seabird)
cce_seabird$year <- as.integer(cce_seabird$year)
unique(cce_seabird$season)
cce_seabird$season <- factor(cce_seabird$season, 
                                levels = c("fall", "wint", "sprg", "summ"))
cce_seabird %>% head()

how many years of data doo we have? do we have data for all 4 seasons?

cce_seabird %>% group_by(year) %>% count()
cce_seabird %>% group_by(season) %>% count()

Calculate Annual Average Bird Density and Richness

annual_seabird <-  cce_seabird %>%
  group_by(year) %>%
  summarise(avg_density=mean(bird_density),
            avg_richness=mean(bird_richness))
cce_seabird %>%
  ggplot(aes(x=year)) +
  geom_line(aes(y=bird_density, color=season), size=1) +
  geom_line(aes(y=avg_density), data=annual_seabird, color="black", size=0.8, linetype="dotdash") +
  labs( x= "Year", y = "Bird Density",
        title = "Seasonal Seabird Density in 1987 - 2006")

cce_seabird %>%
  ggplot(aes(x=year)) +
  geom_line(aes(y=bird_richness, color=season), size=1) +
  geom_line(aes(y=avg_richness), data=annual_seabird, size=0.8, linetype="dotdash") +
  labs( x= "Year", y = "Bird Richness",
        title = "Seasonal Seabird Richness in 1987 - 2006")

density is decreasing for all four seasons, and annually mean

seems like richness has been decreasing till 1997 and then going back

might be result of missing data for some seaons in some year

too many lines, let's see each season separately

cce_seabird %>%
  ggplot(aes(x=year)) +
  geom_line(aes(y=bird_density, color=season), size=1) +
  geom_line(aes(y=avg_density), data=annual_seabird, color="black", size=0.8, linetype="dotdash") +
  labs( x= "Year", y = "Bird Density",
        title = "Seasonal Seabird Density in 1987 - 2006") +
  facet_wrap(~season)

cce_seabird %>%
  ggplot(aes(x=year)) +
  geom_line(aes(y=bird_richness, color=season), size=1) +
  geom_line(aes(y=avg_richness), data=annual_seabird, size=0.8, linetype="dotdash") +
  labs( x= "Year", y = "Bird Richness",
        title = "Seasonal Seabird Richness in 1987 - 2006") +
  facet_wrap(~season)

spring seems always above average

let's see the average based on season

cce_seabird %>%
  group_by(season) %>%
  summarise(avg_density=mean(bird_density),
            avg_richness=mean(bird_richness))

calc difference

seabird <- left_join(cce_seabird, annual_seabird)
head(seabird)
seabird <- seabird %>%
  mutate(diff_density=bird_density-avg_density,
         diff_richness=bird_richness-avg_richness)
head(seabird)

plot by season

seabird %>%
  ggplot(aes(x=year)) +
  geom_point(aes(y=diff_density, color=season)) +
  geom_hline(yintercept=0, linetype="longdash") +
  labs( x= "Year") +
  facet_wrap(~season)

seabird %>%
  ggplot(aes(x=year)) +
  geom_point(aes(y=diff_richness, color=season)) +
  geom_hline(yintercept=0, linetype="longdash") +
  labs( x= "Year") +
  facet_wrap(~season)

spring seems to have higher bird density and richness

is there a relationship between density and richness

cce_seabird %>%
  ggplot(aes(x=bird_density, y=bird_richness)) +
  geom_point(aes(color=season)) +
  geom_point(aes(x=avg_density, y=avg_richness), alpha=0.6, shape=15, data=annual_seabird) +
  labs(x = "Bird Density", y = "Bird Richness",
        title = "Bird Density vs Bird Richness")

cce_seabird %>%
  ggplot(aes(x=bird_density, y=bird_richness)) +
  geom_point(aes(color=season)) +
  #geom_point(aes(x=avg_density, y=avg_richness), alpha=0.6, shape=15, data=annual_seabird) +
  labs(x = "Bird Density", y = "Bird Richness",
        title = "Bird Density vs Bird Richness") +
  facet_wrap(~season)

more density means more richness \ makes sense

bring in data from sea-surface temperature and see if there is any relationship

prep data first (Filter valid data: flag 0 stands for good data)

cce_sst <- cce_sst %>%
  filter(sea_surface_temperature_flag==0) %>%
  filter(!is.na(sea_surface_temperature_c)) %>%
  filter(year>=1980)                            #save computing
cce_sst <- cce_sst %>%
    mutate(month_day=as.Date(paste(2224, month, day, sep = "/" )))

now create season variable (see cce_sst for explanation)

fall_start <- as.Date("2224/09/22")
wint_start <- as.Date("2224/12/21")
sprg_start <- as.Date("2224/3/20")
summ_start <- as.Date("2224/6/20")

cce_sst <- cce_sst %>% mutate(
  season = case_when( month_day>=fall_start &  month_day<wint_start ~ "fall",
                      month_day>=wint_start | month_day<sprg_start  ~ "wint",
                      month_day>=sprg_start &  month_day<summ_start ~ "sprg",
                      month_day>=summ_start &  month_day<fall_start ~ "summ"
                     )
  ) 
cce_sst$season <- factor(cce_sst$season, 
                                levels = c("fall", "wint", "sprg", "summ"))
levels(cce_sst$season)[2:3]
#cce_sst %>% select(date_pst:day, month_day, season)
calculate seasonal temperature
annual_sst<- cce_sst %>%
  group_by(year) %>%
  summarize(annual_temp = mean(sea_surface_temperature_c))
annual_sst %>% head()
seasonal_sst <- cce_sst %>%
  group_by(year, season) %>%
  summarize(seasonal_temp = mean(sea_surface_temperature_c))
seasonal_sst <- left_join(seasonal_sst, annual_sst)
merge data together
bird_sst <- left_join(seabird, seasonal_sst) %>% arrange(year, season)
bird_sst  %>% select(year, season, seasonal_temp, annual_temp)

before exploring relationship, see sst in these years

bird_sst %>%
  ggplot(aes(x=year)) +
  geom_path(aes(y=seasonal_temp, color=season), size=1) +
  geom_path(aes(y=annual_temp)) +
  theme_minimal() +
  labs(x = "Year", y = "Seasonal Sea-Surface Temperature (C)")

see shape

bird_sst %>%
  ggplot(aes(x=year)) +
  geom_path(aes(y=annual_temp), color="blue") +
  geom_path(aes(y=avg_density)) +
  geom_path(aes(y=avg_richness)) +
  scale_x_continuous(breaks = scales::pretty_breaks(n = 10))

there was a drop in sst, density, and richness between arround 96-99

now
bird_sst %>%
  ggplot() +
  geom_point(aes(x=bird_density, y= seasonal_temp, color=season)) +
  geom_point(aes(x=avg_density, y=annual_temp), alpha=0.6, shape=15, size=1)

bird_sst %>%
  ggplot() +
  geom_point(aes(x=bird_density, y= seasonal_temp, color=season)) +
  geom_point(aes(x=avg_density, y=annual_temp), alpha=0.6, shape=15, size=1) +
  facet_wrap(~season)
bird_sst %>%
  ggplot() +
  geom_point(aes(x=bird_richness, y= seasonal_temp, color=season)) +
  geom_point(aes(x=avg_richness, y=annual_temp), alpha=0.6, shape=15)

we see lower bird richness happens when temperature is lower than 18



karenezhao/alohakez documentation built on June 27, 2021, 10:22 p.m.