#' ## Load DImodels package to fit the model
library(DImodels)
## Load data
data(sim2)
## Fit DI model
model1 <- DI(prop = 3:6, DImodel = 'FULL', data = sim2, y = 'response')
## Create visualisation
## If no communities are specified 2 communities at
## each level of richness from the original data are used
prediction_contributions(model1)
## Can also manually specify communities of interest
my_comms <- data.frame(p1 = c(1, 0, 0, 0.5, 1/3, 0.25),
p2 = c(0, 0, 0.5, 0, 1/3, 0.25),
p3 = c(0, 1, 0.5, 0, 1/3, 0.25),
p4 = c(0, 0, 0, 0.5, 0, 0.25))
prediction_contributions(model1, data = my_comms)
## Group contributions to show as a single component on the plot
prediction_contributions(model1, data = my_comms,
groups = list("Interactions" = c("`p1:p2`", "`p1:p3`",
"`p1:p4`", "`p2:p3`",
"`p2:p4`", "`p3:p4`")))
## Add a prediction interval using `se = TRUE` and show bars horizontally
prediction_contributions(model1, data = my_comms, se = TRUE,
bar_orientation = "horizontal",
groups = list("Interactions" = c("`p1:p2`", "`p1:p3`",
"`p1:p4`", "`p2:p3`",
"`p2:p4`", "`p3:p4`")))
## Facet the plot on any variable
my_comms$richness <- c(1, 1, 2, 2, 3, 4)
## Use `facet_var`
prediction_contributions(model1, data = my_comms, facet_var = "richness",
bar_orientation = "horizontal",
groups = list("Interactions" = c("`p1:p2`", "`p1:p3`",
"`p1:p4`", "`p2:p3`",
"`p2:p4`", "`p3:p4`")))
## Can also add additional variables independent of the simplex design
## to get a separate plot for unique combination of the variables
prediction_contributions(model1, data = my_comms,
add_var = list("block" = factor(c(1, 2),
levels = c(1, 2, 3, 4))))
## Manually specify colours and bar labels
## Model has 10 terms but we grouped 6 of them into 1 term,
## so we need to specify 5 colours (4 ungrouped terms + 1 grouped term)
## Bar labels can be specified using `bar_labs`
## Also, using nrow to arrange plots in rows
prediction_contributions(model1, data = my_comms,
colours = c("steelblue1", "steelblue4",
"orange", "orange4",
"grey"),
bar_labs = c("p1 Mono", "p3 Mono", "1/2 p2 p3",
"1/2 p1 p4", "1/3 p1 p2 p3", "Centroid"),
add_var = list("block" = factor(c(1, 2),
levels = c(1, 2, 3, 4))),
nrow = 2,
groups = list("Interactions" = c("`p1:p2`", "`p1:p3`",
"`p1:p4`", "`p2:p3`",
"`p2:p4`", "`p3:p4`")))
## Specify `plot = FALSE` to not create the plot but return the prepared data
head(prediction_contributions(model1, data = my_comms, plot = FALSE,
facet_var = "richness",
bar_orientation = "horizontal"))
Run the code above in your browser using DataLab