View source: R/calculateDistanceBaseline.R
calcEllipseDists | R Documentation |
Calculates distance from ellipse and distance from centroid.
calcEllipseDists(
metadf,
ord,
group = "Time_period",
reflev = "Pre-human",
ordiType = "sd",
addConf = TRUE
)
metadf |
metadata (e.g. groups). Needs to be same length and order as rows that went into ordination. |
ord |
the ordination object. Currently only works with NMDS |
group |
the column in the metadata which contains the grouping variable for the baseline |
reflev |
the value in the column group which is the baseline level |
ordiType |
what sort of ordiellipse? Options are all those which ordiellipse accepts |
addConf |
use 95 CI or not? See ordiellipse options. |
A named list: "distSF" with the distances from baseline as a spatial point object, "distDF", a data.frame version of the same, and "baseline_polygon" an SF object of the reference baseline polygon
data("mite")
data("mite.env")
set.seed(999)
met <- metaMDS(mite, "jaccard", try = 50)
dlist <- calcEllipseDists(metadf = mite.env, ord = met,
group = "Topo", reflev = "Hummock")
par(mfrow = c(2, 2))
plot(met, type = "n")
plot(dlist[["baseline_polygon"]], add = TRUE,
col = adjustcolor("forestgreen", 0.2),
border = NA)
with(dlist[["distDF"]][dlist[["distDF"]]$Topo == "Hummock", ],
points(x = NMDS1, y = NMDS2, col = "forestgreen", pch = 16))
with(dlist[["distDF"]][dlist[["distDF"]]$Topo == "Blanket", ],
points(x = NMDS1, y = NMDS2, col = "black", pch = 16))
legend("topleft", pch = c(16, 16, 15),
col = c("forestgreen", "black",
adjustcolor("forestgreen", 0.5)),
legend = c("Hummock", "Blanket", "95% CI Ellipse"))
mtext(side = 3, "95% CI around centroid calculated")
plot(met, type = "n")
plot(dlist[["baseline_polygon"]], add = TRUE,
col = adjustcolor("forestgreen", 0.2),
border = NA)
mtext(side = 3, "Points sized by distance from baseline")
with(dlist[["distDF"]][
dlist[["distDF"]]$Topo == "Hummock", ],
points(x = NMDS1, y = NMDS2, cex = distEllipse + 0.5,
col = "forestgreen"))
with(dlist[["distDF"]][
dlist[["distDF"]]$Topo == "Blanket", ],
points(x = NMDS1, y = NMDS2, cex = distEllipse + 0.5,
col = "black"))
plot(met, type = "n")
plot(dlist[["baseline_polygon"]], add = TRUE,
col = adjustcolor("forestgreen", 0.2),
border = NA)
mtext(side = 3, "Blanket points by shrub prevalence")
colDF <- data.frame(Shrub = c("None", "Few", "Many"),
cols = I(c("skyblue", "cornflowerblue", "darkblue")))
with(dlist[["distDF"]][dlist[["distDF"]]$Topo == "Hummock", ],
points(x = NMDS1, y = NMDS2, col = "grey"))
with(dlist[["distDF"]][
dlist[["distDF"]]$Topo == "Blanket", ],
points(x = NMDS1, y = NMDS2, col = colDF[
match(Shrub, colDF$Shrub), "cols"]))
legend("topleft", pch = 1, legend = colDF$Shrub, col = colDF$cols)
with(dlist[["distDF"]][dlist[["distDF"]]$Topo == "Blanket", ],
plot(x = Shrub, y = distEllipse, xlab = "Shrub",
ylab = "Distance from baseline"))
mtext(side = 3, "Distance from baseline as a function\nof another col in dataset (shrubs)")
# Example with Boral
## NOTE: As per the boral help, the values below MUST NOT be used in a real application;
## they are only used here to make the examples run quick!!!
example_mcmc_control <- list(n.burnin = 10, n.iteration = 100,
n.thin = 1)
data("mite")
data("mite.env")
miteBoral <- boral::boral(mite, family = "negative.binomial",
mcmc.control = example_mcmc_control,
lv.control = list(num.lv = 2),
row.eff = "fixed",
save.model = FALSE, calc.ics = FALSE)
dlist <- calcEllipseDists(metadf = mite.env, ord = miteBoral,
group = "Topo", reflev = "Hummock")
par(mfrow = c(1, 2))
boral::lvsplot(miteBoral, biplot = FALSE,
col = "transparent",
main = "Boral ordination")
plot(dlist[["baseline_polygon"]], add = TRUE,
col = adjustcolor("forestgreen", 0.2),
border = NA)
plot(st_geometry(dlist[["distSF"]][dlist[["distSF"]]$Topo == "Hummock", ],),
add = TRUE,
col = "forestgreen",
pch = 16
)
plot(st_geometry(dlist[["distSF"]][dlist[["distSF"]]$Topo == "Blanket", ],),
add = TRUE,
col = "black",
pch = 16
)
legend("topleft", pch = c(16, 16, 15),
col = c("forestgreen", "black",
adjustcolor("forestgreen", 0.5)),
legend = c("Hummock", "Blanket", "95% CI Ellipse"))
mtext(side = 3, "95% CI around centroid calculated")
plot(met, type = "n", main = "NMDS ordination")
plot(dlist[["baseline_polygon"]], add = TRUE,
col = adjustcolor("forestgreen", 0.2),
border = NA)
plot(st_geometry(dlist[["distSF"]][dlist[["distSF"]]$Topo == "Hummock", ],),
add = TRUE,
col = "forestgreen",
pch = 16
)
plot(st_geometry(dlist[["distSF"]][dlist[["distSF"]]$Topo == "Blanket", ],),
add = TRUE,
col = "black",
pch = 16
)
legend("topleft", pch = c(16, 16, 15),
col = c("forestgreen", "black",
adjustcolor("forestgreen", 0.5)),
legend = c("Hummock", "Blanket", "95% CI Ellipse"))
mtext(side = 3, "95% CI around centroid calculated")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.