Quality control plot based on Margalef D

to_log("INFO", "Entering subsection 'Quality control plot based on Margalef D'...")
# set minimum number of samples to analyse
# increased from 10 to 20 (advise Willem 2016-09-12)
min_samples <- 20L 

# estimate S and N for each pool
d <- d_mmi %>%
    group_by(OBJECTID, HABITAT, YEAR, POOL_RUN, POOL_ID) %>%
    summarise(
        S = species_richness(taxon = TAXON, count = VALUE),
        N = total_abundance(count = VALUE)
    ) %>%
    mutate(logN = log(N))

# model (S-1) ~ log(N)
d <- d %>%
    group_by(OBJECTID, HABITAT, YEAR) %>%
    do(
        x_logN = seq(from = min(.$logN), to = max(.$logN), length.out = 100), 
        n = nrow(.),
        model = lm(I(S-1) ~ logN, data = .),
        g = ggplot(data = .)
    ) %>%
    ungroup

# unroll n
d$n <- d$n %>% 
    flatten_int

# only create plots for at least a minimum number of samples
d <- d %>% 
    filter(n >= min_samples)




Try the BENMMI package in your browser

Any scripts or data that you put into this service are public.

BENMMI documentation built on Oct. 23, 2020, 8:24 p.m.