library(DImodels)
## Load data
data(sim3)
## Fit model
mod <- glm(response ~ 0 + (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9)^2,
data = sim3)
## Create data
## We have nine (p1 to p9) variables here and using conditional_ternary
## to visualise the simplex space won't be very helpful as there are too
## variables to condition on
## Instead we group the nine-variables into three groups called "G", "L" and "H"
plot_data <- grouped_ternary_data(model = mod,
prop = paste0("p", 1:9),
FG = c("G","G","G","G","G","L","L","H","H"),
resolution = 1)
grouped_ternary_plot(plot_data)
## By default the variables within a group take up an equal share of the
## group proportion. So for example, each point along the above ternary
## would have a 50:50 split of the variables in the group "L" or "H", thus
## the vertex where "L" is 1, would mean that p6 and p7 are 0.5 each,
## similarly, the vertex "H" is made up of 0.5 of p8 and p9 while the "G"
## vertex is comprised of 0.2 of each of p1, p2, p3, p4, and p5. The concepts
## also extend to points along the edges and interior of the ternary.
## Change the proportional split of species within an FG by using `values`
## `values` takes a numeric vector where the position of each element
## describes the proportion of the corresponding species within the
## corresponding FG
## For examples this vector describes, 2-% each of p1, p2, p3, p4 and p5,
## in G, 0% and 100% of p6 and p7, respectively in G2 and 30% and 70% of
## p8 and p9, respectively in G3.
vals <- c(0.2, 0.2, 0.2, 0.2, 0.2,
0, 1,
0.3, 0.7)
plot_data <- grouped_ternary_data(prop = paste0("p", 1:9),
FG = c("G","G","G","G","G","L","L","H","H"),
values = vals,
resolution = 1,
model = mod)
## Change number of contours and colour scheme
grouped_ternary_plot(plot_data,
nlevels = 8,
colours = hcl.colors(8))
## Can also add any additional experimental structures
## Notice .add_str_ID in the data
plot_data <- grouped_ternary_data(prop = paste0("p", 1:9),
FG = c("G","G","G","G","G","L","L","H","H"),
add_var = list("treatment" = c("50", "150")),
values = vals,
model = mod,
resolution = 1)
grouped_ternary_plot(data = plot_data)
Run the code above in your browser using DataLab