## Load DImodels package to fit the model
library(DImodels)
library(dplyr)
## Load data
data(sim4)
sim4 <- sim4 %>% filter(treatment == 50)
## Fit DI model
mod <- DI(prop = 3:8, DImodel = "AV", data = sim4, y = "response") %>%
suppressWarnings()
## Create visualisation
## By default, 'richness' is the gradient and communities from the
## raw data are used to calculate average response
gradient_change(model = mod)
## Specify custom data
gradient_change(model = mod, data = sim4 %>% filter(richness <= 4))
## Create plot for all equi-proportional communities at a
## given level of richness
plot_data <- get_equi_comms(6, variables = paste0("p", 1:6))
gradient_change(model = mod, data = plot_data)
## Can also plot average response across evenness and
## change colours of the pie-slices using `pie_colours`
gradient_change(model = mod, gradient = "evenness",
pie_colours = c("darkolivegreen1", "darkolivegreen4",
"orange1", "orange4",
"steelblue1", "steelblue4"))
## Manually specify only specific communities to be shown as pie-chart
## glyphs using `pie_data` and `facet_var` to facet the plot on
## an additional variable.
gradient_change(model = mod,
pie_data = sim4 %>% filter(richness %in% c(1, 6)),
facet_var = "treatment")
## Use `add_var` to add additional variables independent of the compositions
## Multiple plots will be produced and can be arranged using nrow and ncol
## Create plot arranged in 2 columns
# \donttest{
gradient_change(model = mod,
data = sim4[, -2],
add_var = list("treatment" = c(50, 250)),
pie_data = sim4[, -2] %>% filter(richness %in% c(1, 6)),
ncol = 2)
# }
## Specify `plot = FALSE` to not create the plot but return the prepared data
head(gradient_change(model = mod, plot = FALSE,
pie_data = sim4 %>% filter(richness %in% c(1, 6)),
facet_var = "treatment"))
Run the code above in your browser using DataLab