Trapping vs Spotlighting with Stats
spot_g <- group_by(spot, site)
spot_s <- summarise(spot_g, total_fish = sum(value), species = length(unique(spp)))
site_vec <- c("Confluence", "El Dorado", "Orbells", "The Rookery")
indx <- spot_s$site %in% site_vec
spot_s$region <- ifelse(indx, "Fresh", "Estuary")
spot_aov <- spot_s
spot_g <- group_by(spot_s, region)
spot_s <- summarise(spot_g, mean_fish = mean(total_fish),
sd = sd(total_fish),
n = length(total_fish),
se = se(total_fish))
## Trapping data
minnow$method <- "Minnow"
hinaki$method <- "Hinaki"
all_td <- bind_rows(minnow, hinaki) # td == Trapping data
trap_g <- group_by(all_td, site)
trap_s <- summarise(trap_g, total_fish = sum(value))
site_vec <- c("Confluence", "El Dorado", "Orbells", "Rookery")
indx <- trap_s$site %in% site_vec
trap_s$region <- ifelse(indx, "Fresh", "Estuary")
trap_aov <- trap_s
# Here we overwrite the objects from above.
# If you are going to do any stats on this, you might like to retain it.
trap_g <- group_by(trap_s, region)
trap_s <- summarise(trap_g, mean_fish = mean(total_fish),
sd = sd(total_fish),
n = length(total_fish),
se = se(total_fish))
# Plotting Data
trap_s$method <- "Trapping"
spot_s$method <- "Spotlighting"
pdat <- bind_rows(spot_s, trap_s)
pdat
## # A tibble: 4 × 6
## region mean_fish sd n se method
## <chr> <dbl> <dbl> <int> <dbl> <chr>
## 1 Estuary 31.75 22.020823 4 11.010412 Spotlighting
## 2 Fresh 130.75 105.976019 4 52.988010 Spotlighting
## 3 Estuary 4.00 5.228129 4 2.614065 Trapping
## 4 Fresh 3.50 2.516611 4 1.258306 Trapping
# Error bar = Standard error
p1 <- ggplot(data = pdat, mapping = aes(x = region, y = mean_fish, fill = method,
group = method))
p1 <- p1 + geom_bar(stat = "identity", position = position_dodge(0.9))
p1 <- p1 + geom_errorbar(mapping = aes(ymin = mean_fish-se, ymax = mean_fish+se),
position = position_dodge(0.9), width = 0.2)
p1 <- p1 + theme_few() + scale_fill_brewer(palette = "Dark2", name = "Method")
p1 <- p1 + xlab("Region") + ylab("Mean Number of Fish")
#p1 <- p1 + ggtitle("Average number of fish sampled with each method")
p1

ggsave("./figures/trapping_vs_spot.png", width = 21, height = 29.7/3, units = "cm")
# 2-way ANOVA
trap_aov$method <- "Trapping"
spot_aov$method <- "Spotlighting"
aov_dat <- bind_rows(trap_aov, spot_aov)
# The underlying model:
m1 <- lm(data = aov_dat, total_fish~region*method)
summary(m1);
##
## Call:
## lm(formula = total_fish ~ region * method, data = aov_dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -113.750 -4.000 0.250 5.688 125.250
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.75 27.10 1.172 0.2641
## regionFresh 99.00 38.32 2.583 0.0240 *
## methodTrapping -27.75 38.32 -0.724 0.4829
## regionFresh:methodTrapping -99.50 54.20 -1.836 0.0913 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 54.2 on 12 degrees of freedom
## Multiple R-squared: 0.5531, Adjusted R-squared: 0.4414
## F-statistic: 4.951 on 3 and 12 DF, p-value: 0.01833
anova(m1);
## Analysis of Variance Table
##
## Response: total_fish
## Df Sum Sq Mean Sq F value Pr(>F)
## region 1 9702 9702.2 3.3030 0.09419 .
## method 1 24025 24025.0 8.1791 0.01436 *
## region:method 1 9900 9900.2 3.3704 0.09126 .
## Residuals 12 35248 2937.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
sink(file = "./output/trapping_vs_spot_2way.txt")
print(summary(m1))
##
## Call:
## lm(formula = total_fish ~ region * method, data = aov_dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -113.750 -4.000 0.250 5.688 125.250
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.75 27.10 1.172 0.2641
## regionFresh 99.00 38.32 2.583 0.0240 *
## methodTrapping -27.75 38.32 -0.724 0.4829
## regionFresh:methodTrapping -99.50 54.20 -1.836 0.0913 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 54.2 on 12 degrees of freedom
## Multiple R-squared: 0.5531, Adjusted R-squared: 0.4414
## F-statistic: 4.951 on 3 and 12 DF, p-value: 0.01833
cat("\n\n")
print(anova(m1))
## Analysis of Variance Table
##
## Response: total_fish
## Df Sum Sq Mean Sq F value Pr(>F)
## region 1 9702 9702.2 3.3030 0.09419 .
## method 1 24025 24025.0 8.1791 0.01436 *
## region:method 1 9900 9900.2 3.3704 0.09126 .
## Residuals 12 35248 2937.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
sink()
Diversity vs Site
non_zero_sum <- function(x){
sum(as.logical(x))
}
div_g <- group_by(spot, site, spp)
div_spot <- summarise(div_g, fish_sum = sum(value)) #, species = unique(spp)
spot_tot <- reshape2::dcast(div_spot, site~spp, value.var = 'fish_sum', fill = 0)
spot_tot
## site Black Flounder Brown Trout Common Bully Common Smelt
## 1 Confluence 2 10 155 0
## 2 El Dorado 0 14 0 0
## 3 Orbells 0 1 51 1
## 4 Rail Bridge 0 0 0 0
## 5 River Mouth 0 0 0 0
## 6 State HW 1 1 0 0 0
## 7 The Rookery 1 2 40 0
## 8 Waka Landing 0 0 0 0
## Giant Bully Inanga Longfin Eel Mullet Shortfin Eel Triplefin
## 1 0 84 3 0 1 0
## 2 0 0 2 0 0 0
## 3 1 121 0 0 0 0
## 4 0 27 0 0 0 10
## 5 0 0 0 0 0 2
## 6 0 30 0 6 0 18
## 7 0 31 0 0 0 0
## 8 0 23 0 0 0 10
## Unidentified Eel
## 1 1
## 2 1
## 3 0
## 4 0
## 5 0
## 6 0
## 7 1
## 8 0
spot_tot$n_unique <- apply(spot_tot[,-1], MARGIN = 1, FUN = non_zero_sum)
div_g <- group_by(minnow, site, spp)
div_minnow <- summarise(div_g, fish_sum = sum(value)) #, species = unique(spp)
minnow_tot <- reshape2::dcast(div_minnow, site~spp, value.var = 'fish_sum', fill = 0)
minnow_tot
## site Common Bully Inanga Triplefin
## 1 Confluence 4 3 0
## 2 El Dorado 0 0 0
## 3 Orbells 0 2 0
## 4 Rail Bridge 0 0 0
## 5 River Mouth 0 0 0
## 6 Rookery 0 1 0
## 7 State Highway 1 0 1 10
## 8 Waka Landing Site 0 0 5
minnow_tot$n_unique <- apply(minnow_tot[,-1], MARGIN = 1, FUN = non_zero_sum)
div_g <- group_by(hinaki, site, spp)
div_hinaki <- summarise(div_g, fish_sum = sum(value)) #, species = unique(spp)
hinaki_tot <- reshape2::dcast(div_hinaki, site~spp, value.var = 'fish_sum', fill = 0)
hinaki_tot
## site Longfin Eel Shortfin Eel
## 1 Confluence 0 0
## 2 El Dorado 3 0
## 3 Orbells 1 0
## 4 Rail Bridge 0 0
## 5 River Mouth 0 0
## 6 Rookery 0 0
## 7 State Highway 1 0 0
## 8 Waka Landing Site 0 0
hinaki_tot$n_unique <- apply(hinaki_tot[,-1], MARGIN = 1, FUN = non_zero_sum)
minnow_tot$method <- "Minnow"
hinaki_tot$method <- "Hinaki"
trap_tot <- hinaki_tot$n_unique + minnow_tot$n_unique
trap_tot
## [1] 2 1 2 0 0 1 2 1
spot_g2 <- group_by(spot_tot, site)
spot_s2 <- summarise(spot_g2)
trap_s2 <- summarise(spot_g2)
spot_s2$n_unique <- spot_tot$n_unique
trap_s2$n_unique <- trap_tot
spot_s2$method <- "Spotlighting"
trap_s2$method <- "Trapping"
spot_s2
## # A tibble: 8 × 3
## site n_unique method
## <chr> <int> <chr>
## 1 Confluence 7 Spotlighting
## 2 El Dorado 3 Spotlighting
## 3 Orbells 5 Spotlighting
## 4 Rail Bridge 2 Spotlighting
## 5 River Mouth 1 Spotlighting
## 6 State HW 1 4 Spotlighting
## 7 The Rookery 5 Spotlighting
## 8 Waka Landing 2 Spotlighting
trap_s2
## # A tibble: 8 × 3
## site n_unique method
## <chr> <int> <chr>
## 1 Confluence 2 Trapping
## 2 El Dorado 1 Trapping
## 3 Orbells 2 Trapping
## 4 Rail Bridge 0 Trapping
## 5 River Mouth 0 Trapping
## 6 State HW 1 1 Trapping
## 7 The Rookery 2 Trapping
## 8 Waka Landing 1 Trapping
all_data_div <- bind_rows(spot_s2, trap_s2) # td == Trapping data
site_vec <- c("Confluence", "El Dorado", "Orbells", "The Rookery")
indx <- all_data_div$site %in% site_vec
all_data_div$region <- ifelse(indx, "Fresh", "Estuary")
all_data_div
## # A tibble: 16 × 4
## site n_unique method region
## <chr> <int> <chr> <chr>
## 1 Confluence 7 Spotlighting Fresh
## 2 El Dorado 3 Spotlighting Fresh
## 3 Orbells 5 Spotlighting Fresh
## 4 Rail Bridge 2 Spotlighting Estuary
## 5 River Mouth 1 Spotlighting Estuary
## 6 State HW 1 4 Spotlighting Estuary
## 7 The Rookery 5 Spotlighting Fresh
## 8 Waka Landing 2 Spotlighting Estuary
## 9 Confluence 2 Trapping Fresh
## 10 El Dorado 1 Trapping Fresh
## 11 Orbells 2 Trapping Fresh
## 12 Rail Bridge 0 Trapping Estuary
## 13 River Mouth 0 Trapping Estuary
## 14 State HW 1 1 Trapping Estuary
## 15 The Rookery 2 Trapping Fresh
## 16 Waka Landing 1 Trapping Estuary
lord <- c("River Mouth", "Rail Bridge", "Waka Landing", "State HW 1" ,
"Orbells", "The Rookery", "Confluence", "El Dorado")
all_data_div$siteF <- factor(all_data_div$site, levels = lord)
p2 <- ggplot(data = all_data_div, mapping = aes(x = siteF, y = n_unique, fill = method,
group = method))
p2 <- p2 + geom_bar(stat = "identity", position = position_dodge(0.9))
p2 <- p2 + theme_few() + scale_fill_brewer(palette = "Dark2", name = "Method")
p2 <- p2 + xlab("ocean <-- Site --> upstream") + ylab("Total No of Species of Fish Found")
#p2 <- p2 + ggtitle("Diversity of species by site")
p2 <- p2 + theme(axis.text.x = element_text(angle = 90, hjust = 0, vjust = 0))
p2

ggsave("./figures/diversity vs site.png", width = 21, height = 29.7/3, units = "cm")
Farming Impact vs Catch
habitat_g = group_by(habitat, site)
habitat_g
## Source: local data frame [824 x 6]
## Groups: site [9]
##
## row_name col_name value site stock_access h
## <chr> <chr> <dbl> <chr> <int> <chr>
## 1 Measure 1 (Dwn) A Stream Width (m) 12.6 Confluence 10 Width
## 2 Measure 2 (Cntr) A Stream Width (m) 10.8 Confluence 10 Width
## 3 Measure 3 (Up) A Stream Width (m) 15.2 Confluence 10 Width
## 4 Measure 1 (Dwn) B Stream Width (m) 15.2 Confluence 10 Width
## 5 Measure 2 (Cntr) B Stream Width (m) 14.3 Confluence 10 Width
## 6 Measure 3 (Up) B Stream Width (m) 9.3 Confluence 10 Width
## 7 Measure 1 (Dwn) C Stream Width (m) 9.3 Confluence 10 Width
## 8 Measure 2 (Cntr) C Stream Width (m) 11.1 Confluence 10 Width
## 9 Measure 3 (Up) C Stream Width (m) 8.5 Confluence 10 Width
## 10 Measure 1 (Dwn) D Stream Width (m) 8.5 Confluence 10 Width
## # ... with 814 more rows
hab_g <- group_by(habitat, site)
hab_s <- summarise(hab_g, stock_access = mean(stock_access))
site_vec <- c("Confluence", "El Dorado", "Orbells", "The Rookery")
indx <- hab_s$site %in% site_vec
hab_s$region <- ifelse(indx, "Fresh", "Estuary")
hab_s <- hab_s[-9,] # great coding right here eh
# hab_s <- hab_s[-8,]
# hab_s <- hab_s[-6,]
# hab_s <- hab_s[-5,]
# hab_s <- hab_s[-4,]
hab_s
## # A tibble: 8 × 3
## site stock_access region
## <chr> <dbl> <chr>
## 1 Confluence 10 Fresh
## 2 El Dorado 3 Fresh
## 3 Orbells 0 Fresh
## 4 Rail NA Estuary
## 5 River mouth NA Estuary
## 6 State highway 1 NA Estuary
## 7 The Rookery 0 Fresh
## 8 Waka Landing NA Estuary
spot_g
## Source: local data frame [8 x 4]
## Groups: region [2]
##
## site total_fish species region
## <chr> <int> <int> <chr>
## 1 Confluence 256 9 Fresh
## 2 El Dorado 17 9 Fresh
## 3 Orbells 175 9 Fresh
## 4 Rail Bridge 37 11 Estuary
## 5 River Mouth 2 11 Estuary
## 6 State HW 1 55 11 Estuary
## 7 The Rookery 75 9 Fresh
## 8 Waka Landing 33 11 Estuary
trap_g
## Source: local data frame [8 x 3]
## Groups: region [2]
##
## site total_fish region
## <chr> <int> <chr>
## 1 Confluence 7 Fresh
## 2 El Dorado 3 Fresh
## 3 Orbells 3 Fresh
## 4 Rail Bridge 0 Estuary
## 5 River Mouth 0 Estuary
## 6 Rookery 1 Fresh
## 7 State Highway 1 11 Estuary
## 8 Waka Landing Site 5 Estuary
spot_g3 <- group_by(spot_g, site)
spot_s3 <- summarise(spot_g3, total_fish)
trap_g3 <- trap_g
spot_s3
## # A tibble: 8 × 2
## site total_fish
## <chr> <int>
## 1 Confluence 256
## 2 El Dorado 17
## 3 Orbells 175
## 4 Rail Bridge 37
## 5 River Mouth 2
## 6 State HW 1 55
## 7 The Rookery 75
## 8 Waka Landing 33
hab_s
## # A tibble: 8 × 3
## site stock_access region
## <chr> <dbl> <chr>
## 1 Confluence 10 Fresh
## 2 El Dorado 3 Fresh
## 3 Orbells 0 Fresh
## 4 Rail NA Estuary
## 5 River mouth NA Estuary
## 6 State highway 1 NA Estuary
## 7 The Rookery 0 Fresh
## 8 Waka Landing NA Estuary
spot_s3$sa <- hab_s$stock_access
spot_s3
## # A tibble: 8 × 3
## site total_fish sa
## <chr> <int> <dbl>
## 1 Confluence 256 10
## 2 El Dorado 17 3
## 3 Orbells 175 0
## 4 Rail Bridge 37 NA
## 5 River Mouth 2 NA
## 6 State HW 1 55 NA
## 7 The Rookery 75 0
## 8 Waka Landing 33 NA
# trap_s3 <- trap_g3
#
# all_td_hab <- bind_rows(spot_s3, trap_s3)
# all_td_hab
lord2 <- c("Orbells", "The Rookery", "Confluence", "El Dorado")
spot_s3$siteF <- factor(spot_s3$site, levels = lord)
p3 <- ggplot(data = spot_s3, mapping = aes(x = sa, y = total_fish))
p3 <- p3 + geom_point()
p3 <- p3 + theme_few() + scale_fill_brewer(palette = "Dark2", name = "Method")
p3 <- p3 + xlab("Stock access, 1-10") + ylab("Total No of Fish Found")
p3 <- p3 + geom_text(aes(label=site), vjust=0.25, hjust="inward")
#p3 <- p3 + ggtitle("Stock access vs fish spotlighted")
p3 <- p3 + scale_x_continuous(breaks=c(0:10))
p3
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_text).

ggsave("./figures/fish sum vs farming impact.png", width = 21, height = 29.7/3, units = "cm")
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_text).