knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(MCE)                                               # Load the package
library(dplyr)                                             # Load some data manipulation tools

data.frame(Light = seq(0.001, 1, length = 500)) %>%        # Choose light levels
  mutate("Bright depths" = depth(Light),                   # Calculate depths
         "Shaded depths" = depth(Light, shade = 0.25),     # Calculate depths with shading
         "Shallow community" = shallow(Light),             # Shallow community at these light levels
         "Mesophotic community" = mesophotic(Light),       # Mesophotic community at these light levels
         "Whole reef" = reef(Light)) -> depth.distribution # Calculate reef-wide community values

As the default light levels are shared across all the functions, specifying a set of light levels isn't really neccessary. You would get the same result not specifying Light anywhere in the above code. I think including it helps to show how things are working, and makes the code more readable.

The following table show's the values we simulated.

knitr::kable(depth.distribution[1:5,], format="html") %>% 
  kableExtra::kable_styling(bootstrap_options = "striped", full_width = T)

We don't actually need to go to the effort of simulating a reef to get the boundary depths between the shallow, upper mesophotic, and lower mesophotic zones. MCE comes with a built in reef_boundary function which returns the light level where a patch of reef would look just as much shallow as it does mesophotic.

If we pass this light level to the depth function, we can then get the shallowest and deepest depths where the two communities overlap. This is the same as identifying the upper and lower limits of the upper mesophotic zone.

boundaries <- data.frame(Boundary = c("lower", "upper"),
                         Depth = c(depth(reef_boundary()), depth(reef_boundary(), shade = 0.25)))
knitr::kable(boundaries, format="html") %>% 
  kableExtra::kable_styling(bootstrap_options = "striped", full_width = T)
library(ggplot2)

ggplot(depth.distribution, aes(y= `Bright depths`, x= `Whole reef`)) + 
  annotate("rect", xmin=-1,xmax=0, ymin=-Inf,
           ymax=Inf, fill="steelblue2", alpha=0.75)+                # Box from -1 to 0
  annotate("rect", xmin=0, xmax=1, ymin=-Inf,
           ymax=Inf, fill="tan2", alpha=0.75)+                      # Box from 0 to 1
  geom_ribbon(data = depth.distribution, aes(ymin = `Shaded depths`, ymax = `Bright depths`, x= `Whole reef`), colour = 
                'white', fill = 'White', alpha = 0.45) +            # Add model range
  geom_point(data = boundaries, aes(x = 0, y = Depth)) +
  labs(y = 'Depth (m)', x = 'Net D value') +  
  coord_cartesian(ylim = c(100, 0), xlim = c(-0.65,0.65), ) +
  annotate("text", label="Shallow", y=93, x=-0.35, col="Black")+
  annotate("text", label="observations", y=100, x=-0.35, col="Black")+
  annotate("text", label="Mesophotic", y=93, x=0.35, col="Black")+
  annotate("text", label="observations", y=100, x=0.35, col="Black")+
  theme_minimal() +                        
  theme(plot.title = element_text(size=12, hjust = 0.5),    
        axis.title.x = element_text(size=10),  
        axis.title.y = element_text(size=10), 
        legend.position = 'bottom') +                              # label sizes and legend position
  NULL


Jack-H-Laverick/MCE documentation built on May 9, 2020, 3:58 p.m.