knitr::opts_chunk$set(echo = FALSE)
library(drake)
library(dplyr)
library(ggplot2)

all_di <- read.csv(here::here("analysis", "reports", "all_di_old.csv"), stringsAsFactors = F)

all_di <- all_di %>%
  mutate(log_nparts = log(gmp:::as.double.bigz(nparts)),
         log_nsamples = log(nsamples),
         log150_nparts = log(gmp:::as.double.bigz(nparts), base = 150)) %>%
  mutate(prop_found = exp(log_nsamples - log_nparts)) %>%
  mutate(found_all = prop_found==1) %>%
  filter(s0 >= 2,
         n0 > s0,
         dat %in% c("bbs", "gentry", "fia_short", "fia_small", "mcdb", "misc_abund_short")) %>%
  mutate(dat = ifelse(substr(dat, 0, 3) == "fia", yes = "fia", no = dat)) %>%
  mutate(dat = ifelse(dat == "misc_abund_short", "misc_abund", dat))%>%
  mutate(is_fia = ifelse(substr(dat, 0, 3) == "fia", dat, "other"))

Datasets in S by N space

ggplot(filter(all_di, !singletons), aes(log(s0), log(n0), color = dat)) +
  geom_point(alpha = .3) +
  theme_bw() +
  ggtitle("Communities by S and N") +
  scale_color_viridis_d()

Narrowness schematic

Provisionally copied from dissertation proposal.

Percentile histograms by dataset

ggplot(filter(all_di, !singletons, s0 > 2), aes(skew_percentile)) +
  geom_histogram(bins = 100) +
  theme_bw() +
  facet_wrap(vars(dat), scales = "free_y") +
  geom_vline(xintercept = 95, color = "red", linetype = 3) +
  ggtitle("Observed percentile: Skewness")


ggplot(filter(all_di, !singletons), aes(simpson_percentile)) +
  geom_histogram(bins = 100) +
  theme_bw() +
  facet_wrap(vars(dat), scales = "free_y") +
  geom_vline(xintercept = 5, color = "red", linetype = 3) +
  ggtitle("Observed percentile: Evenness")

Rarefaction effect

rarefact <- all_di %>%
  select(singletons, skew_percentile, simpson_percentile, dat, site, s0) %>%
  tidyr::pivot_wider(names_from = singletons, values_from = c(skew_percentile, simpson_percentile, s0))

gridExtra::grid.arrange(grobs = list(ggplot(filter(rarefact, s0_FALSE  > 3), aes(skew_percentile_FALSE, skew_percentile_TRUE)) + 
  geom_point(alpha = .05) +
  geom_abline(intercept = 0, slope = 1, color = "blue") +
  theme_bw() +
  facet_wrap(vars(dat)) +
  ggtitle("Rarefaction change: Skewness"),

ggplot(rarefact, aes(simpson_percentile_FALSE, simpson_percentile_TRUE)) + 
  geom_point(alpha = .05) +
  geom_abline(intercept = 0, slope = 1, color = "blue") +
  theme_bw() +
  facet_wrap(vars(dat)) +
  ggtitle("Rarefaction change: Evenness")), ncol = 2)

Percentile by S and N

fia_s_range <- range(filter(all_di, !singletons, dat == "fia")$s0)
fia_n_range <- range(filter(all_di, !singletons, dat == "fia")$n0)

fia_border <- data.frame(
  s0 = c(0, fia_s_range[2], fia_s_range[2]),
  n0 = c(fia_n_range[2], fia_n_range[2], 0)
)

gridExtra::grid.arrange(grobs = list(
ggplot(filter(all_di, !singletons, s0 > 3), aes(log(s0), log(n0), color = skew_percentile)) +
  geom_point(alpha = .15) +
  geom_path(data = fia_border, aes(log(s0), log(n0)), color = "black") +
  theme_bw() +
  scale_color_viridis_c(option = "plasma", end = .8) +
  ggtitle("Skewness percentile over S and N"),
ggplot(filter(all_di, !singletons), aes(log(s0), log(n0), color = simpson_percentile)) +
  geom_point(alpha = .15) +
  theme_bw() +
  scale_color_viridis_c(option = "plasma", end = .8) +
    geom_path(data = fia_border, aes(log(s0), log(n0)), color = "black") +
  ggtitle("Evenness percentile over S and N")),
ncol= 2)

FIA v other small communities

small <- filter(all_di, !singletons, s0 <= fia_s_range[2], n0 <= fia_n_range[2])

gridExtra::grid.arrange(grobs = list(
ggplot(filter(small, !singletons, s0 > 2, log_nparts > log(50)), aes(skew_percentile)) +
  geom_histogram(bins = 100) +
  theme_bw() +
  facet_wrap(vars(is_fia), scales = "free_y") +
  geom_vline(xintercept = 95, color = "red", linetype = 3) +
  ggtitle("Small communities percentile: Skewness"),


ggplot(filter(small, !singletons, s0 > 2), aes(skew_percentile)) +
  geom_histogram(bins = 100) +
  theme_bw() +
  facet_wrap(vars(is_fia), scales = "free_y") +
  geom_vline(xintercept = 95, color = "red", linetype = 3) +
  ggtitle("Small communities percentile: Skewness")#,

# 
# ggplot(filter(small, !singletons), aes(simpson_percentile)) +
#   geom_histogram(bins = 100) +
#   theme_bw() +
#   facet_wrap(vars(is_fia), scales = "free_y") +
#   geom_vline(xintercept = 5, color = "red", linetype = 3) +
#   ggtitle("Small communities percentile: Evenness")
), ncol = 1)

small %>%
  filter(s0 > 2) %>%
  group_by(is_fia) %>%
  summarize(prop_skew_high = mean(skew_percentile > 95),
            nsites = dplyr::n())


small %>%
  filter(s0 > 2, nparts > 50) %>%
  group_by(is_fia) %>%
  summarize(prop_skew_high = mean(skew_percentile > 95),
            nsites = dplyr::n())

small %>%
  group_by(is_fia) %>%
  summarize(prop_even_low = mean(simpson_percentile < 5),
            nsites = dplyr::n())

small %>%
    filter(s0 > 2, nparts > 50) %>%
  group_by(is_fia) %>%
  summarize(prop_even_low = mean(simpson_percentile < 5),
            nsites = dplyr::n())

95 interval by S and N

gridExtra::grid.arrange(grobs = list(
  ggplot(filter(all_di, !singletons, s0 > 2), 
         aes(log(s0), log(n0), color = skew_95_ratio_1t)) +
    geom_point(alpha = .2) +
    scale_color_viridis_c() +
    theme_bw() +
    ggtitle("95% ratio: Skewness") +
        geom_path(data = fia_border, aes(log(s0), log(n0)), color = "black") +

    theme(legend.position = "bottom"),
   ggplot(filter(all_di, !singletons), 
         aes(log(s0), log(n0), color = simpson_95_ratio_1t)) +
    geom_point(alpha = .2) +
    scale_color_viridis_c() +
    theme_bw() +
    ggtitle("95% ratio: Evenness") +
        geom_path(data = fia_border, aes(log(s0), log(n0)), color = "black") +

    theme(legend.position = "bottom")
),
ncol = 2)


diazrenata/scadsanalysis documentation built on May 14, 2021, 6:59 p.m.