| Title: | 'ggplot2' Plots for the 'vegan' Package |
|---|---|
| Description: | Functions to produce 'ggplot2'-based plots of objects produced by functions in the 'vegan' package. Provides fortify(), autoplot(), and tidy() methods for many of 'vegan''s functions. The aim of 'ggvegan' is to make it easier to work within the 'tidyverse' with 'vegan'. |
| Authors: | Gavin L. Simpson [aut, cre] (ORCID: <https://orcid.org/0000-0002-9084-8413>), Jari Oksanen [aut] (ORCID: <https://orcid.org/0000-0001-7102-9626>), Didzis Elferts [ctb] (ORCID: <https://orcid.org/0000-0002-9401-1231>) |
| Maintainer: | Gavin L. Simpson <[email protected]> |
| License: | GPL-2 |
| Version: | 0.2.1.9 |
| Built: | 2026-05-22 10:25:20 UTC |
| Source: | https://github.com/gavinsimpson/ggvegan |
Adds a biplot arrow layer to an existing plot
add_biplot_arrows(object, plt, vars, arrow.col = "navy")add_biplot_arrows(object, plt, vars, arrow.col = "navy")
object |
an ordination object. |
plt |
a ggplot object. |
vars |
character; length 2 vector of dimension names. |
arrow.col |
colour specification for biplot arrows and their labels. |
Adds a biplot arrow layer to an existing plot
add_biplot_centroids(object, plt, vars, arrow.col = "navy")add_biplot_centroids(object, plt, vars, arrow.col = "navy")
object |
an ordination object. |
plt |
a ggplot object. |
vars |
character; length 2 vector of dimension names. |
arrow.col |
colour specification for biplot arrows and their labels. |
Adds species and site score layers to an existing plot
add_spp_site_scores(object, plt, vars, geom, draw_list, arrows)add_spp_site_scores(object, plt, vars, geom, draw_list, arrows)
object |
an ordination object. |
plt |
a ggplot object. |
vars |
character; length 2 vector of dimension names. |
geom |
character; vector of length 1 or 2 indicating which geom will be used for the species or site scores. |
draw_list |
logical; vector of types of scores indicating which are available and requested for plotting. |
arrows |
logical; length 1 vector indicating if species scores should be drawn using arrows. |
Scale vector arrows to fill proportion of the data.
arrow_mul(arrows, data, at = c(0, 0), fill = 0.75)arrow_mul(arrows, data, at = c(0, 0), fill = 0.75)
arrows |
a two-column matrix-like object containing coordinates for the arrows/vectors on x and y axes. |
data |
a two-column matrix-like object containing coordinates of the data on the x and y axes. |
at |
numeric vector of length 2; location of the origin of the arrows. |
fill |
numeric; what proportion of the range of the data to fill |
a numeric multiplier that will scale the arrows
Gavin L. Simpson
Function adds layers of fitted vectors and centroids of factor
levels in an ordiggplot() graph.
## S3 method for class 'envfit' autolayer( object, text = TRUE, box = FALSE, arrow.mul = 1, arrow.params = list(), text.params = list(), ... )## S3 method for class 'envfit' autolayer( object, text = TRUE, box = FALSE, arrow.mul = 1, arrow.params = list(), text.params = list(), ... )
object |
|
text |
add text to plot (logical). |
box |
write text on a non-transparent label (logical). |
arrow.mul |
arrow multiplier. |
arrow.params, text.params
|
List of additional parameters to
|
... |
Other parameters passed to all graphical functions
|
Function adds a previosly fitted vegan::envfit() model. This does
not adapt to changes in the ordiggplot() object, for instance in
scaling or axes, but it must re-fitted for a changed model.
Returns ggplot2 layers geom_segment for arrows and
geom_text or geom_label for their text labels (when
appropriate), and another layer of geom_text or geom_label
for the centroids of factor leves (when appropriate). The score
type is called envfit.
Jari Oksanen
library(vegan) library(ggplot2) data(mite, mite.env, package = "vegan") mod <- cca(mite) ## you must have same scaling in envfit() and ordiggplot() ef <- envfit(mod ~ Shrub+Topo+WatrCont+SubsDens, mite.env, scaling = "sites") ordiggplot(mod, scaling="sites") + geom_ordi_axis() + geom_ordi_point("sites") + autolayer(ef, arrow.mul=1.3, col="navy", box=TRUE, text.params=list(mapping=aes(fontface="bold")))library(vegan) library(ggplot2) data(mite, mite.env, package = "vegan") mod <- cca(mite) ## you must have same scaling in envfit() and ordiggplot() ef <- envfit(mod ~ Shrub+Topo+WatrCont+SubsDens, mite.env, scaling = "sites") ordiggplot(mod, scaling="sites") + geom_ordi_axis() + geom_ordi_point("sites") + autolayer(ef, arrow.mul=1.3, col="navy", box=TRUE, text.params=list(mapping=aes(fontface="bold")))
Function adds vegan::ordisurf() results to an graph.
## S3 method for class 'ordisurf' autolayer( object, fill = FALSE, contour.params = list(), fill.params = list(), ... )## S3 method for class 'ordisurf' autolayer( object, fill = FALSE, contour.params = list(), fill.params = list(), ... )
object |
|
fill |
Use filled ordination space where raster colour match the fitted values of the surface (logical). |
contour.params, fill.params
|
Arguments passed to
|
... |
Other arguments passed both to |
Function draws contours of fitted vegan::ordisurf() surface and
(optionally) a raster of the surface using ggplot2::geom_contour()
and ggplot2::geom_raster().
Function uses gridded values of ordination plane saved within the
vegan::ordisurf() result instead of scores data from an
ordination object. Therefore its results can be added to any
ordination graph, also from autoplot methods. However, you must
be careful with using exactly the same axes and scaling in
vegan::ordisurf() object and ordination.
Surface fill is non-transparent and will paint over all previous
layers. Filled surface should be used before other visible layers,
or fill should be made transparent with alpha in argument
fill.params passed to ggplot2::geom_raster().
Returns ggplot2 layers geom_contour and geom_raster
(optionally).
Jari Oksanen
library(vegan) library(ggplot2) data(mite, mite.env, package="vegan") mod <- cca(mite) surf <- ordisurf(mod ~ WatrCont, mite.env, plot = FALSE) ordiggplot(mod) + geom_ordi_point("sites", size = mite.env$WatrCont/100) + autolayer(surf) + autolayer(envfit(mod ~ WatrCont, mite.env, permutations=0), arrow.mul = 1.3)library(vegan) library(ggplot2) data(mite, mite.env, package="vegan") mod <- cca(mite) surf <- ordisurf(mod ~ WatrCont, mite.env, plot = FALSE) ordiggplot(mod) + geom_ordi_point("sites", size = mite.env$WatrCont/100) + autolayer(surf) + autolayer(envfit(mod ~ WatrCont, mite.env, permutations=0), arrow.mul = 1.3)
"anosim"
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::anosim().
## S3 method for class 'anosim' autoplot( object, notch = TRUE, varwidth = TRUE, xlab = NULL, ylab = NULL, title = "Analysis of similarities", subtitle = NULL, caption = bquote(R == .(r) * "," ~ P == .(p)), ... )## S3 method for class 'anosim' autoplot( object, notch = TRUE, varwidth = TRUE, xlab = NULL, ylab = NULL, title = "Analysis of similarities", subtitle = NULL, caption = bquote(R == .(r) * "," ~ P == .(p)), ... )
object |
an object of class |
notch |
logical; make notched (default) or standard box plot? |
varwidth |
logical; make box width proportional to the square-root of the number of observations in the group (default)? |
xlab |
character; label for the x-axis. |
ylab |
character; label for the y-axis. |
title |
character; title for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
... |
additional arguments passed to other methods. |
A ggplot object.
Didzis Elferts. Modifications by Gavin L. Simpson.
library("vegan") data(dune) data(dune.env) dune.dist <- vegdist(dune) dune.ano <- with(dune.env, anosim(dune.dist, Management)) autoplot(dune.ano, notch = FALSE)library("vegan") data(dune) data(dune.env) dune.dist <- vegdist(dune) dune.ano <- with(dune.env, anosim(dune.dist, Management)) autoplot(dune.ano, notch = FALSE)
"cca"
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::cca() or vegan::capscale().
## S3 method for class 'cca' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("species", "sites", "biplot", "centroids"), legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, arrow.col = "navy", ... )## S3 method for class 'cca' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("species", "sites", "biplot", "centroids"), legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, arrow.col = "navy", ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geom to use for the species (variables) and
sites (samples) layers. A vector of length 2; if a vector of length 1,
|
layers |
character; which scores to plot as layers |
legend.position |
character or two-element numeric vector; where to
position the legend. See |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
ylab |
character; label for the y-axis. |
xlab |
character; label for the x-axis. |
arrow.col |
colour specification for biplot arrows and their labels. |
... |
Additional arguments passed to the |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) autoplot(sol)library("vegan") data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) autoplot(sol)
"dbrda"
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::dbrda().
## S3 method for class 'dbrda' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("sites", "biplot", "centroids"), legend.position = "none", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, const = NULL, arrow.col = "navy", ... )## S3 method for class 'dbrda' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("sites", "biplot", "centroids"), legend.position = "none", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, const = NULL, arrow.col = "navy", ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geom to use for the site (sample) scores. One
of |
layers |
character; which scores to plot as layers |
legend.position |
character or two-element numeric vector; where to
position the legend. See |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
ylab |
character; label for the y-axis. |
xlab |
character; label for the x-axis. |
const |
General scaling constant to |
arrow.col |
colour specification for biplot arrows and their labels. |
... |
Additional arguments passed to the |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(dune, dune.env) dune_dbrda <- dbrda( dune ~ A1 + Moisture + Use + Management, data = dune.env ) autoplot(dune_dbrda)library("vegan") data(dune, dune.env) dune_dbrda <- dbrda( dune ~ A1 + Moisture + Use + Management, data = dune.env ) autoplot(dune_dbrda)
"decorana"
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::decorana().
## S3 method for class 'decorana' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("sites", "species"), legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab, xlab, ... )## S3 method for class 'decorana' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("sites", "species"), legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab, xlab, ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geom to use for the species (variables) and
sites (samples) layers. A vector of length 2; if a vector of length 1,
|
layers |
character; which scores to plot as layers |
legend.position |
character or two-element numeric vector; where to
position the legend. See |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
ylab |
character; label for the y-axis. |
xlab |
character; label for the x-axis. |
... |
Additional arguments passed to |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(dune) sol <- decorana(dune) autoplot(sol) autoplot(sol, layers = "species", geom = "text")library("vegan") data(dune) sol <- decorana(dune) autoplot(sol) autoplot(sol, layers = "species", geom = "text")
envfit objectsProduces a multi-layer ggplot object representing the output of objects
produced by vegan::envfit().
## S3 method for class 'envfit' autoplot( object, geom = c("label", "text", "label_repel", "text_repel"), line.col = "black", xlab = NULL, ylab = NULL, title = NULL, subtitle = NULL, caption = NULL, ... )## S3 method for class 'envfit' autoplot( object, geom = c("label", "text", "label_repel", "text_repel"), line.col = "black", xlab = NULL, ylab = NULL, title = NULL, subtitle = NULL, caption = NULL, ... )
object |
an object of class |
geom |
character; which geom to use to label vectors and factor centroids. |
line.col |
colour with which to draw vectors. |
xlab |
character; label for the x-axis. |
ylab |
character; label for the y-axis. |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
... |
additional arguments passed to |
A ggplot object.
Gavin L. Simpson
library("vegan") data(varespec, varechem) ord1 <- metaMDS(varespec) fit1 <- envfit(ord1, varechem, perm = 199) autoplot(fit1, geom = 'label_repel') data(dune, dune.env) ord2 <- cca(dune) fit2 <- envfit(ord2 ~ Moisture + A1, dune.env, perm = 199) autoplot(fit2)library("vegan") data(varespec, varechem) ord1 <- metaMDS(varespec) fit1 <- envfit(ord1, varechem, perm = 199) autoplot(fit1, geom = 'label_repel') data(dune, dune.env) ord2 <- cca(dune) fit2 <- envfit(ord2 ~ Moisture + A1, dune.env, perm = 199) autoplot(fit2)
Draws a bar plot of species rank abundance with Fisher's log-series superimposed.
## S3 method for class 'fisherfit' autoplot( object, show.fitted = TRUE, xlab = "Abundance", ylab = "Number of Species", title = "Fisher's log-series distribution", bar.col = NA, bar.fill = "grey35", line.col = "red", linewidth = 0.7, subtitle = NULL, caption = NULL, ... )## S3 method for class 'fisherfit' autoplot( object, show.fitted = TRUE, xlab = "Abundance", ylab = "Number of Species", title = "Fisher's log-series distribution", bar.col = NA, bar.fill = "grey35", line.col = "red", linewidth = 0.7, subtitle = NULL, caption = NULL, ... )
object |
an object of class |
show.fitted |
logical; should the estimated distribution also be plotted? |
xlab |
character; label for the x axis. |
ylab |
character; label for the y axis. |
title |
character; subtitle for the plot. |
bar.col |
colour for the bar outlines. The default, |
bar.fill |
fill colour for the bars. |
line.col |
colour for Fisher's log-series curve. |
linewidth |
numeric; linewidth aesthetic for the log-series curve. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
... |
additional arguments passed to other methods. |
A ggplot object.
Gavin L. Simpson
library("vegan") data(BCI) mod <- fisherfit(BCI[5,]) autoplot(mod)library("vegan") data(BCI) mod <- fisherfit(BCI[5,]) autoplot(mod)
"isomap"
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::isomap().
## S3 method for class 'isomap' autoplot( object, axes = c(1, 2), geom = c("point", "text"), network = TRUE, line.col = "grey85", linewidth = 0.7, xlab = NULL, ylab = NULL, title = "Isometric feature mapping", subtitle = NULL, caption = NULL, ... )## S3 method for class 'isomap' autoplot( object, axes = c(1, 2), geom = c("point", "text"), network = TRUE, line.col = "grey85", linewidth = 0.7, xlab = NULL, ylab = NULL, title = "Isometric feature mapping", subtitle = NULL, caption = NULL, ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geom to use for the MDS scores layer. |
network |
logical; should the edges of the ISOMAP network be drawn? |
line.col |
colour with which to draw the network edges. |
linewidth |
numeric; linewidth aesthetic for the log-series curve. |
xlab |
character; label for the x-axis. |
ylab |
character; label for the y-axis. |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
... |
additional arguments passed to other methods. |
A ggplot object.
Gavin L. Simpson
library("vegan") data(BCI) dis <- vegdist(BCI) ord <- isomap(dis, k = 3) autoplot(ord) autoplot(ord, geom = "text")library("vegan") data(BCI) dis <- vegdist(BCI) ord <- isomap(dis, k = 3) autoplot(ord) autoplot(ord, geom = "text")
"metaMDS"
Produces a multi-layer ggplot object representing the output of
objects produced by vegan::metaMDS().
## S3 method for class 'metaMDS' autoplot( object, geom = c("point", "text"), layers = c("species", "sites"), legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab, xlab, ... )## S3 method for class 'metaMDS' autoplot( object, geom = c("point", "text"), layers = c("species", "sites"), legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab, xlab, ... )
object |
an object of class |
geom |
character; which geom to use for the species (variables) and
sites (samples) layers. A vector of length 2; if a vector of length 1,
|
layers |
character; which scores to plot as layers |
legend.position |
character or two-element numeric vector; where to
position the legend. See |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
ylab |
character; label for the y-axis. |
xlab |
character; label for the x-axis. |
... |
Additional arguments passed to |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(dune) sol <- metaMDS(dune) autoplot(sol)library("vegan") data(dune) sol <- metaMDS(dune) autoplot(sol)
Alternatives for lattice graphics functions
vegan::densityplot.permustats(),
vegan::densityplot.permustats() and
vegan::boxplot.permustats().
## S3 method for class 'permustats' autoplot( object, plot = c("box", "violin", "density", "qqnorm"), scale = FALSE, facet = FALSE, gg.params = list(), ... )## S3 method for class 'permustats' autoplot( object, plot = c("box", "violin", "density", "qqnorm"), scale = FALSE, facet = FALSE, gg.params = list(), ... )
object |
object from |
plot |
character; the type of plot, or a geom from ggplot2. |
scale |
logical; use standardized effect sizes (SES)? |
facet |
logical; should the plot be faceted by |
gg.params |
list; arguments passed to function drawing the box-like
object. Depending on argument |
... |
Other parameters passed to functions (ignored). |
Function fortify() returns a data frame with variables permutations
(numeric) and term (factor labelling the permutation). The result of
fortify() can be used to custom build diagnostic plots. autoplot()
provides basic plots of vegan::permustats() objects with limited
flexibility.
Returns a ggplot object.
library("vegan") data(dune, dune.env) mod <- cca(dune ~ A1 + Management + Moisture, dune.env) (ano <- anova(mod, by = "onedf")) pstat <- permustats(ano) head(fortify(pstat)) autoplot(pstat, "box") if (requireNamespace("ggplot2")) { library("ggplot2") # avoid overplotting x-axis text autoplot(pstat, "violin") + scale_x_discrete(guide = guide_axis(n.dodge = 2)) autoplot(pstat, "qqnorm", facet = TRUE) + geom_qq_line() } autoplot(pstat, "density", facet = TRUE)library("vegan") data(dune, dune.env) mod <- cca(dune ~ A1 + Management + Moisture, dune.env) (ano <- anova(mod, by = "onedf")) pstat <- permustats(ano) head(fortify(pstat)) autoplot(pstat, "box") if (requireNamespace("ggplot2")) { library("ggplot2") # avoid overplotting x-axis text autoplot(pstat, "violin") + scale_x_discrete(guide = guide_axis(n.dodge = 2)) autoplot(pstat, "qqnorm", facet = TRUE) + geom_qq_line() } autoplot(pstat, "density", facet = TRUE)
"poolaccum"
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::poolaccum().
## S3 method for class 'poolaccum' autoplot( object, facet = TRUE, ribbon = facet, ncol = NULL, ribbon.alpha = 0.3, xlab = "Size", ylab = "Richness", title = "Accumulated species richness", subtitle = NULL, caption = NULL, ... )## S3 method for class 'poolaccum' autoplot( object, facet = TRUE, ribbon = facet, ncol = NULL, ribbon.alpha = 0.3, xlab = "Size", ylab = "Richness", title = "Accumulated species richness", subtitle = NULL, caption = NULL, ... )
object |
an object of class |
facet |
logical; should extrapolated richness estimators be shown in separate facets? |
ribbon |
logical; show the quantile-based uncertainty interval? Uses
|
ncol |
numeric; if faceting the plot, how many columns to use. Default arguments will result in three columns. |
ribbon.alpha |
numeric; alpha transparency used for the uncertainty
interval. Passed to the |
xlab |
character; label for the x axis. |
ylab |
character; label for the y axis. |
title |
character; title for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
... |
additional arguments passed to |
A ggplot object.
Didzis Elferts & Gavin L. Simpson
library("vegan") data(BCI) pool <- poolaccum(BCI) autoplot(pool) ## Turn off facetting; turns off ribbon too autoplot(pool, facet = FALSE)library("vegan") data(BCI) pool <- poolaccum(BCI) autoplot(pool) ## Turn off facetting; turns off ribbon too autoplot(pool, facet = FALSE)
"prc"
Produces a multi-layer ggplot object representing the output of
objects produced by vegan::prc().
## S3 method for class 'prc' autoplot( object, select, xlab, ylab, title = NULL, subtitle = NULL, caption = NULL, legend.position = "top", ... )## S3 method for class 'prc' autoplot( object, select, xlab, ylab, title = NULL, subtitle = NULL, caption = NULL, legend.position = "top", ... )
object |
an object inheriting from class |
select |
a logical vector where |
xlab |
character; label for the x-axis |
ylab |
character; label for the y-axis |
title |
character; subtitle for the plot |
subtitle |
character; subtitle for the plot |
caption |
character; caption for the plot |
legend.position |
character; position for the legend grob. See argument
|
... |
Additional arguments passed to |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(pyrifos) week <- gl(11, 12, labels=c(-4, -1, 0.1, 1, 2, 4, 8, 12, 15, 19, 24)) dose <- factor(rep(c(0.1, 0, 0, 0.9, 0, 44, 6, 0.1, 44, 0.9, 0, 6), 11)) ## Fit PRC model mod <- prc(pyrifos, dose, week) ## plot want <- colSums(pyrifos) >= 300 autoplot(mod, select = want)library("vegan") data(pyrifos) week <- gl(11, 12, labels=c(-4, -1, 0.1, 1, 2, 4, 8, 12, 15, 19, 24)) dose <- factor(rep(c(0.1, 0, 0, 0.9, 0, 44, 6, 0.1, 44, 0.9, 0, 6), 11)) ## Fit PRC model mod <- prc(pyrifos, dose, week) ## plot want <- colSums(pyrifos) >= 300 autoplot(mod, select = want)
Draws a bar plot of species rank abundance with Preston's log-normal model superimposed.
## S3 method for class 'prestonfit' autoplot( object, show.fitted = TRUE, xlab = "Abundance", ylab = "Number of Species", title = "Preston's lognormal distribution", subtitle = NULL, caption = NULL, bar.col = NA, bar.fill = "grey35", line.col = "red", linewidth = 0.7, ... )## S3 method for class 'prestonfit' autoplot( object, show.fitted = TRUE, xlab = "Abundance", ylab = "Number of Species", title = "Preston's lognormal distribution", subtitle = NULL, caption = NULL, bar.col = NA, bar.fill = "grey35", line.col = "red", linewidth = 0.7, ... )
object |
an object of class |
show.fitted |
logical; should the estimated distribution also be plotted? |
xlab |
character; label for the x axis. |
ylab |
character; label for the y axis. |
title |
character; title for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
bar.col |
colour for the bar outlines. The default, 'NA“, does not draw outlines around bars. |
bar.fill |
fill colour for the bars. |
line.col |
colour for Preston's log-normal curve. |
linewidth |
numeric; size aesthetic for the log-normal curve. |
... |
additional arguments passed to other methods. |
A ggplot object.
Gavin L. Simpson
library("vegan") data(BCI) pfit <- prestonfit(colSums(BCI)) autoplot(pfit)library("vegan") data(BCI) pfit <- prestonfit(colSums(BCI)) autoplot(pfit)
ggplot2 graphics for Rank-Abundance Distribution models
fitted with vegan functions vegan::radfit() or produced
with vegan::as.rad().
## S3 method for class 'radfit' autoplot( object, facet = TRUE, point.params = list(), line.params = list(), ... ) ## S3 method for class 'radfit.frame' autoplot(object, point.params = list(), line.params = list(), ...) ## S3 method for class 'radline' autoplot(object, point.params = list(), line.params = list(), ...) ## S3 method for class 'rad' autoplot(object, point.params = list(), line.params = list(), ...) ## S3 method for class 'rad.frame' autoplot(object, point.params = list(), highlight = NULL, ...)## S3 method for class 'radfit' autoplot( object, facet = TRUE, point.params = list(), line.params = list(), ... ) ## S3 method for class 'radfit.frame' autoplot(object, point.params = list(), line.params = list(), ...) ## S3 method for class 'radline' autoplot(object, point.params = list(), line.params = list(), ...) ## S3 method for class 'rad' autoplot(object, point.params = list(), line.params = list(), ...) ## S3 method for class 'rad.frame' autoplot(object, point.params = list(), highlight = NULL, ...)
object |
Result object from |
facet |
Draw each fitted model to a separate facet or (if
|
point.params, line.params
|
Parameters to modify points or
lines (passed to |
... |
Additional arguments passed to the functions. |
highlight |
Names of species that should be highlighted as coloured points. |
The ggplot2::autoplot() function draws graphics which are ggplot2
alternatives for lattice graphics in vegan. In
addition, there are functions for vegan::as.rad()
results which do not have dedicated graphics invegan.
Returns a ggplot object.
Jari Oksanen
library(vegan) library(ggplot2) data(mite) m1 <- radfit(mite[1, ]) ## With logarithmic y-axis (default) Pre-emption model is a line autoplot(m1) + labs(title="log-Abundance: Pre-emption model is a line") ## With log-log scale, Zipf model is a line autoplot(m1) + scale_x_log10() + labs(title="log-log Scale: Zipf model is a line") ## Show only the best model autoplot(m1, pick = "AIC") ## Show selected models in one frame autoplot(m1, pick = c("Z","M","L"), facet=FALSE) ## plot best models for several sites m <- radfit(mite[1:12,]) autoplot(m) + labs(title = "Model Selection AIC (Default)") ## use BIC and reorder sites by their diversity autoplot(m, pick="BIC", order.by = diversity(mite[1:12,])) + labs(title="Model Selection BIC, Ordered by Increasing Diversity") ## Plot RAD models without fits highlighting most abundant species in the ## whole data. m0 <- as.rad(mite[1:12,]) dominants <- names(sort(colSums(mite), decreasing = TRUE))[1:6] autoplot(m0, highlight = dominants)library(vegan) library(ggplot2) data(mite) m1 <- radfit(mite[1, ]) ## With logarithmic y-axis (default) Pre-emption model is a line autoplot(m1) + labs(title="log-Abundance: Pre-emption model is a line") ## With log-log scale, Zipf model is a line autoplot(m1) + scale_x_log10() + labs(title="log-log Scale: Zipf model is a line") ## Show only the best model autoplot(m1, pick = "AIC") ## Show selected models in one frame autoplot(m1, pick = c("Z","M","L"), facet=FALSE) ## plot best models for several sites m <- radfit(mite[1:12,]) autoplot(m) + labs(title = "Model Selection AIC (Default)") ## use BIC and reorder sites by their diversity autoplot(m, pick="BIC", order.by = diversity(mite[1:12,])) + labs(title="Model Selection BIC, Ordered by Increasing Diversity") ## Plot RAD models without fits highlighting most abundant species in the ## whole data. m0 <- as.rad(mite[1:12,]) dominants <- names(sort(colSums(mite), decreasing = TRUE))[1:6] autoplot(m0, highlight = dominants)
'rda'
Produces a multi-layer ggplot object representing the output of objects
produced by vegan::rda().
## S3 method for class 'rda' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("species", "sites", "biplot", "centroids"), arrows = TRUE, legend.position = "none", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, const = NULL, arrow.col = "navy", ... )## S3 method for class 'rda' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("species", "sites", "biplot", "centroids"), arrows = TRUE, legend.position = "none", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, const = NULL, arrow.col = "navy", ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geom to use for the species (variables) and
sites (samples) layers. A vector of length 2; if a vector of length 1,
|
layers |
character; which scores to plot as layers |
arrows |
logical; represent species (variables) using vectors? |
legend.position |
character or two-element numeric vector; where to
position the legend. See |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
ylab |
character; label for the y-axis. |
xlab |
character; label for the x-axis. |
const |
General scaling constant to |
arrow.col |
colour specification for biplot arrows and their labels. |
... |
Additional arguments passed to the |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(dune) pca <- rda(dune) autoplot(pca) ## Just the species scores autoplot(pca, layers = "species")library("vegan") data(dune) pca <- rda(dune) autoplot(pca) ## Just the species scores autoplot(pca, layers = "species")
"vegan_pco"
Produces a multi-layer ggplot object representing the output of
objects produced by vegan::pco().
## S3 method for class 'vegan_pco' autoplot( object, geom = "point", legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, ... )## S3 method for class 'vegan_pco' autoplot( object, geom = "point", legend.position = "right", title = NULL, subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, ... )
object |
an object of class |
geom |
character; which geom to use for the site (sample) scores. One
of |
legend.position |
character or two-element numeric vector; where to
position the legend. See |
title |
character; subtitle for the plot. |
subtitle |
character; subtitle for the plot. |
caption |
character; caption for the plot. |
ylab |
character; label for the y-axis. |
xlab |
character; label for the x-axis. |
... |
Additional arguments passed to the |
TODO
Returns a ggplot object.
Gavin L. Simpson
library("vegan") data(dune) sol <- pco(dune) autoplot(sol)library("vegan") data(dune) sol <- pco(dune) autoplot(sol)
Check user-supplied layers against list of valid layers
check_user_layers(user, valid, message = FALSE)check_user_layers(user, valid, message = FALSE)
user |
character; vector of user supplied layer names. |
valid |
character; vector of valid layer names. |
message |
logical; should a message be raised in the case of invalid user-supplied layer names. |
Prepares a fortified version of results from vegan::anosim()
objects.
## S3 method for class 'anosim' fortify(model, data, ...) ## S3 method for class 'anosim' tidy(x, data, ...)## S3 method for class 'anosim' fortify(model, data, ...) ## S3 method for class 'anosim' tidy(x, data, ...)
model, x
|
an object of class |
data |
original data set. Currently ignored. |
... |
additional arguments for other methods. Currently ignored. |
A data frame with columns Rank and Class with ranks of
dissimilarity.
Original implementation by Didzis Elferts. Modification to tibbles by Gavin L. Simpson.
library("vegan") library("ggplot2") data(dune, dune.env) dune.dist <- vegdist(dune) dune.ano <- with(dune.env, anosim(dune.dist, Management)) df <- fortify(dune.ano) ggplot(df, aes(x = class, y = rank)) + geom_boxplot(notch = FALSE, varwidth = TRUE)library("vegan") library("ggplot2") data(dune, dune.env) dune.dist <- vegdist(dune) dune.ano <- with(dune.env, anosim(dune.dist, Management)) df <- fortify(dune.ano) ggplot(df, aes(x = class, y = rank)) + geom_boxplot(notch = FALSE, varwidth = TRUE)
"cca" object.Fortifies an object of class "cca" to produce a
data frame of the selected axis scores in long format, suitable for
plotting with ggplot2::ggplot().
## S3 method for class 'cca' fortify(model, data, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "cn"), ...) ## S3 method for class 'cca' tidy(x, data, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "cn"), ...)## S3 method for class 'cca' fortify(model, data, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "cn"), ...) ## S3 method for class 'cca' tidy(x, data, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "cn"), ...)
model, x
|
an object of class |
data |
currently ignored. |
axes |
numeric; which axes to extract scores for. |
layers |
character; the scores to extract in the fortified object.
Passed to |
... |
additional arguments passed to |
TODO
A data frame (tibble) in long format containing the ordination
scores. The first two components are score (the type of score in each
row) and label (the text label to use on plots for this row). The
remaining columns are the extracted ordination axis scores.
Gavin L. Simpson
library("vegan") data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) head(fortify(sol))library("vegan") data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) head(fortify(sol))
"dbrda" object.Fortifies an object of class "dbrda" to produce a
data frame of the selected axis scores in long format, suitable for
plotting with ggplot2::ggplot().
## S3 method for class 'dbrda' fortify( model, data = NULL, axes = 1:6, layers = c("wa", "lc", "bp", "reg", "cn"), const = NULL, ... ) ## S3 method for class 'dbrda' tidy( x, data = NULL, axes = 1:6, layers = c("wa", "lc", "bp", "reg", "cn"), const = NULL, ... )## S3 method for class 'dbrda' fortify( model, data = NULL, axes = 1:6, layers = c("wa", "lc", "bp", "reg", "cn"), const = NULL, ... ) ## S3 method for class 'dbrda' tidy( x, data = NULL, axes = 1:6, layers = c("wa", "lc", "bp", "reg", "cn"), const = NULL, ... )
model, x
|
an object of class |
data |
currently ignored. |
axes |
numeric; which axes to extract scores for. |
layers |
character; the scores to extract in the fortified object.
Passed to |
const |
NULL; General scaling constant to RDA scores. See
|
... |
additional arguments passed to |
TODO
A data frame (tibble) in long format containing the ordination
scores. The first two components are score (the type of score in each
row) and label (the text label to use on plots for this row). The
remaining columns are the extracted ordination axis scores.
Gavin L. Simpson
library("vegan") data(dune) data(dune.env) sol <- dbrda(dune ~ A1 + Management, data = dune.env) head(fortify(sol))library("vegan") data(dune) data(dune.env) sol <- dbrda(dune ~ A1 + Management, data = dune.env) head(fortify(sol))
"decorana" object.Fortifies an object of class "decorana" to produce a data
frame of the selected axis scores in long format, suitable for plotting
with ggplot2::ggplot().
## S3 method for class 'decorana' fortify(model, data, axes = 1:4, layers = c("sites", "species"), ...) ## S3 method for class 'decorana' tidy(x, data, axes = 1:4, layers = c("sites", "species"), ...)## S3 method for class 'decorana' fortify(model, data, axes = 1:4, layers = c("sites", "species"), ...) ## S3 method for class 'decorana' tidy(x, data, axes = 1:4, layers = c("sites", "species"), ...)
model, x
|
an object of class |
data |
currently ignored. |
axes |
numeric; which axis scores are required? |
layers |
character; the scores to extract in the fortified object. |
... |
additional arguments passed to |
TODO
A data frame in long format containing the ordination scores. The first two components are the axis scores.
Gavin L. Simpson
library("vegan") data(dune) sol <- decorana(dune) head(fortify(sol)) head(fortify(sol, layers = "species"))library("vegan") data(dune) sol <- decorana(dune) head(fortify(sol)) head(fortify(sol, layers = "species"))
envfit objectsProduces a tidy data frame from the results of an
vegan::envfit() object.
## S3 method for class 'envfit' fortify(model, data, ...) ## S3 method for class 'envfit' tidy(x, data, ...)## S3 method for class 'envfit' fortify(model, data, ...) ## S3 method for class 'envfit' tidy(x, data, ...)
model, x
|
an object of class |
data |
additional data to augment the |
... |
arguments passed to |
A data frame with columns label, type, containing the label for,
and whether each row refers to, the fitted vector or factor. Remaining
variables are coordinates on the respective ordination axes returned by
vegan::scores.envfit().
Gavin L. Simpson
library("vegan") data(varespec, varechem) ord <- metaMDS(varespec) fit <- envfit(ord, varechem, perm = 199) fortify(fit) data(dune, dune.env) ord <- ca(dune) fit <- envfit(ord ~ Moisture + A1, dune.env, perm = 199) fortify(fit)library("vegan") data(varespec, varechem) ord <- metaMDS(varespec) fit <- envfit(ord, varechem, perm = 199) fortify(fit) data(dune, dune.env) ord <- ca(dune) fit <- envfit(ord ~ Moisture + A1, dune.env, perm = 199) fortify(fit)
Prepares a data frame of results from a vegan::fisherfit())
object suitable for plotting with ggplot2::ggplot()).
## S3 method for class 'fisherfit' fortify(model, data, ...) ## S3 method for class 'fisherfit' tidy(x, data, ...)## S3 method for class 'fisherfit' fortify(model, data, ...) ## S3 method for class 'fisherfit' tidy(x, data, ...)
model, x
|
an object of class |
data |
original data set. Currently ignored. |
... |
other arguments pass to methods. Currently ignored. |
A data frame with columns 'Rank' and 'Abundance'. Additionally,
Fisher's and the nuisance parameter are returned as
attributes 'alpha' and 'k' respectively.
Gavin L. Simpson
library("vegan") data(BCI) mod <- fisherfit(BCI[5,]) head(fortify(mod))library("vegan") data(BCI) mod <- fisherfit(BCI[5,]) head(fortify(mod))
Prepares fortified versions of results from vegan::isomap()
objects.
## S3 method for class 'isomap' fortify(model, data = NULL, axes = NULL, what = c("sites", "network"), ...) ## S3 method for class 'isomap' tidy(x, data = NULL, axes = NULL, what = c("sites", "network"), ...)## S3 method for class 'isomap' fortify(model, data = NULL, axes = NULL, what = c("sites", "network"), ...) ## S3 method for class 'isomap' tidy(x, data = NULL, axes = NULL, what = c("sites", "network"), ...)
model, x
|
an object of class |
data |
data.frame; additional data to be added to the fortified object. |
axes |
numeric; which axes to return. For |
what |
character; what aspect of the results should be fortified?
|
... |
additional arguments for other methods. Currently ignored. |
Two different objects can be created from the results of an
vegan::isomap() object. The first is the standard scores representation
of fortified ordinations in vegan, which results in a wide data frame
where rows contain observations and column the coordinates of observations
on the MDS axes. Because ISOMAP also produces a network or sorts, the
coordinates of the edges of the network can also be returned in a tidy
format using what = "network".
A data frame. For what = "sites", the data frame contains one
variable per dimension of the multidimensional scaling embedding of the
dissimilarities. Variables are named "DimX" with "X" being an integer.
An additional variable is label, containing a label for each observation.
For what = "network", the data frame contains four variables containing
the coordinates in the chosen MDS axes for the start and end points of the
network edges.
Gavin L. Simpson
library("vegan") library("ggplot2") data(BCI) dis <- vegdist(BCI) ord <- isomap(dis, k = 3) df <- fortify(ord, data = data.frame(Richness = specnumber(BCI))) net <- fortify(ord, what = "network", axes = 1:2) ggplot(df, aes(x = dim1, y = dim2)) + geom_segment(data = net, aes(x = xfrom, y = yfrom, xend = xto, yend = yto), colour = "grey85", size = 0.8) + geom_point(aes(size = Richness)) + coord_fixed()library("vegan") library("ggplot2") data(BCI) dis <- vegdist(BCI) ord <- isomap(dis, k = 3) df <- fortify(ord, data = data.frame(Richness = specnumber(BCI))) net <- fortify(ord, what = "network", axes = 1:2) ggplot(df, aes(x = dim1, y = dim2)) + geom_segment(data = net, aes(x = xfrom, y = yfrom, xend = xto, yend = yto), colour = "grey85", size = 0.8) + geom_point(aes(size = Richness)) + coord_fixed()
"mataMDS" object.Fortifies an object of class "metaMDS" to produce a
data frame of the selected axis scores in long format, suitable for
plotting with ggplot2::ggplot().
## S3 method for class 'metaMDS' fortify(model, data, axes = 1:2, layers = c("sites", "species"), ...) ## S3 method for class 'metaMDS' tidy(x, data, layers = c("sites", "species"), ...)## S3 method for class 'metaMDS' fortify(model, data, axes = 1:2, layers = c("sites", "species"), ...) ## S3 method for class 'metaMDS' tidy(x, data, layers = c("sites", "species"), ...)
model, x
|
an object of class |
data |
currently ignored. |
axes |
numeric; which axes to extract scores for. |
layers |
character; the scores to extract in the fortified object.
Passed to |
... |
additional arguments passed to
|
TODO
A data frame in long format containing the ordination scores. The first two components are the axis scores.
Gavin L. Simpson
library("vegan") data(dune) ord <- metaMDS(dune) head(fortify(ord))library("vegan") data(dune) ord <- metaMDS(dune) head(fortify(ord))
Fortify permutation statistics
## S3 method for class 'permustats' fortify(model, data, scale = FALSE, ...) ## S3 method for class 'permustats' tidy(x, data, scale = FALSE, ...)## S3 method for class 'permustats' fortify(model, data, scale = FALSE, ...) ## S3 method for class 'permustats' tidy(x, data, scale = FALSE, ...)
model, x
|
an object of created by |
data |
original data set. Currently ignored. |
scale |
logical; return standardized effect sizes (SES)? |
... |
Other parameters passed to functions (ignored). |
A tibble with columns permutations, and terms containing the
values of tests statistics under the null hypothesis, and a factor
labelling the permutation, respectively.
library("vegan") data(dune, dune.env, package = "vegan") mod <- adonis2(dune ~ Management + A1, data = dune.env) ## use permustats perm <- permustats(mod)library("vegan") data(dune, dune.env, package = "vegan") mod <- adonis2(dune ~ Management + A1, data = dune.env) ## use permustats perm <- permustats(mod)
Prepares a fortified version of results from
vegan::poolaccum() objects.
## S3 method for class 'poolaccum' fortify(model, data, alpha = 0.05, ...) ## S3 method for class 'poolaccum' tidy(x, data, alpha = 0.05, ...)## S3 method for class 'poolaccum' fortify(model, data, alpha = 0.05, ...) ## S3 method for class 'poolaccum' tidy(x, data, alpha = 0.05, ...)
model, x
|
an object of class |
data |
original data set. Currently ignored. |
alpha |
level of quantiles for envelopes shown (default 0.05). |
... |
additional arguments passed to |
A data frame with columns index, size, richness, lower,
upper, and std_dev, containing the richness index, permutation richness
estimator, sample size, upper and lower
quantile interval, and standard deviation of permutation estimates,
respectively.
Gavin L. Simpson & Didzis Elferts
library("vegan") library("ggplot2") data(BCI) pool <- poolaccum(BCI) df <- fortify(pool) df ggplot(df, aes(x = size, y = richness, colour = index)) + geom_ribbon(aes(ymin = lower, ymax = upper, x = size, fill = index), alpha = 0.3, inherit.aes = FALSE) + geom_line() + facet_wrap(~ index)library("vegan") library("ggplot2") data(BCI) pool <- poolaccum(BCI) df <- fortify(pool) df ggplot(df, aes(x = size, y = richness, colour = index)) + geom_ribbon(aes(ymin = lower, ymax = upper, x = size, fill = index), alpha = 0.3, inherit.aes = FALSE) + geom_line() + facet_wrap(~ index)
"prc" objectFortifies an object of class "prc" to produce a data frame of the selected
axis scores in long format, suitable for plotting with ggplot2::ggplot().
## S3 method for class 'prc' fortify(model, data, scaling = "symmetric", axis = 1, ...) ## S3 method for class 'prc' tidy(x, data, scaling = "symmetric", axis = 1, ...)## S3 method for class 'prc' fortify(model, data, scaling = "symmetric", axis = 1, ...) ## S3 method for class 'prc' tidy(x, data, scaling = "symmetric", axis = 1, ...)
model, x
|
an object of class |
data |
currently ignored. |
scaling |
the desired scaling. See |
axis |
numeric; which PRC axis to extract. Default is |
... |
additional arguments currently ignored. |
TODO
A data frame in long format containing the ordination scores. The
first three components are the Time, Treatment, and associated
Response. The last two components, score and label are an indicator
factor and a label for the rows for use in plotting.
Gavin L. Simpson
library("vegan") data(pyrifos) week <- gl(11, 12, labels=c(-4, -1, 0.1, 1, 2, 4, 8, 12, 15, 19, 24)) dose <- factor(rep(c(0.1, 0, 0, 0.9, 0, 44, 6, 0.1, 44, 0.9, 0, 6), 11)) ditch <- gl(12, 1, length=132) pyrifos_prc <- prc(pyrifos, dose, week) fortify(pyrifos_prc)library("vegan") data(pyrifos) week <- gl(11, 12, labels=c(-4, -1, 0.1, 1, 2, 4, 8, 12, 15, 19, 24)) dose <- factor(rep(c(0.1, 0, 0, 0.9, 0, 44, 6, 0.1, 44, 0.9, 0, 6), 11)) ditch <- gl(12, 1, length=132) pyrifos_prc <- prc(pyrifos, dose, week) fortify(pyrifos_prc)
Prepares a data frame of results from a vegan::prestonfit()
object suitable for plotting with ggplot2::ggplot().
## S3 method for class 'prestonfit' fortify(model, data, ...) ## S3 method for class 'prestonfit' tidy(x, data, ...)## S3 method for class 'prestonfit' fortify(model, data, ...) ## S3 method for class 'prestonfit' tidy(x, data, ...)
model, x
|
an object of class |
data |
original data set. Currently ignored. |
... |
other arguments pass to methods. Currently ignored. |
A data frame with columns 'Octave'`` and 'Abundance'“.
Gavin L. Simpson
library("vegan") data(BCI) pfit <- prestonfit(colSums(BCI)) fortify(pfit)library("vegan") data(BCI) pfit <- prestonfit(colSums(BCI)) fortify(pfit)
Prepares a fortified version of results from
vegan::radfit() or vegan::as.rad().
## S3 method for class 'radfit' fortify(model, data, pick = NULL, ...) ## S3 method for class 'radfit.frame' fortify(model, data, pick = "AIC", order.by = NULL, ...) ## S3 method for class 'radline' fortify(model, data, ...) ## S3 method for class 'rad' fortify(model, data, ...) ## S3 method for class 'rad.frame' fortify(model, data, order.by = NULL, ...) ## S3 method for class 'radfit' tidy(x, data, pick = NULL, ...) ## S3 method for class 'radfit.frame' tidy(x, data, pick = "AIC", order.by = NULL, ...) ## S3 method for class 'radline' tidy(x, data, ...) ## S3 method for class 'rad' tidy(x, data, ...) ## S3 method for class 'rad.frame' tidy(x, data, order.by = NULL, ...)## S3 method for class 'radfit' fortify(model, data, pick = NULL, ...) ## S3 method for class 'radfit.frame' fortify(model, data, pick = "AIC", order.by = NULL, ...) ## S3 method for class 'radline' fortify(model, data, ...) ## S3 method for class 'rad' fortify(model, data, ...) ## S3 method for class 'rad.frame' fortify(model, data, order.by = NULL, ...) ## S3 method for class 'radfit' tidy(x, data, pick = NULL, ...) ## S3 method for class 'radfit.frame' tidy(x, data, pick = "AIC", order.by = NULL, ...) ## S3 method for class 'radline' tidy(x, data, ...) ## S3 method for class 'rad' tidy(x, data, ...) ## S3 method for class 'rad.frame' tidy(x, data, order.by = NULL, ...)
model |
model or other R object to convert to data frame |
data |
original dataset, if needed |
pick |
Pick or several models. Allowed values are |
... |
Arguments passed to methods. |
order.by |
A vector used for ordering site panels. |
x |
An object to be converted into a tidy |
A data frame or tibble which in all cases has columns
species (character), for species names, with rank and
abundance for data, and may also have columns site (factor)
for site names when several sites were analysed, fit of
fitted abundances when evaluated, and model (factor) when
several models were fitted.
Jari Oksanen
"rda" object.Fortifies an object of class "rda" to produce a
data frame of the selected axis scores in long format, suitable for
plotting with ggplot2::ggplot().
## S3 method for class 'rda' fortify( model, data = NULL, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "cn"), const = NULL, ... ) ## S3 method for class 'rda' tidy( x, data = NULL, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "reg", "cn"), const = NULL, ... )## S3 method for class 'rda' fortify( model, data = NULL, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "cn"), const = NULL, ... ) ## S3 method for class 'rda' tidy( x, data = NULL, axes = 1:6, layers = c("sp", "wa", "lc", "bp", "reg", "cn"), const = NULL, ... )
model, x
|
an object of class |
data |
currently ignored. |
axes |
numeric; which axes to extract scores for. |
layers |
character; the scores to extract in the fortified object.
Passed to |
const |
NULL; General scaling constant to RDA scores. See
|
... |
additional arguments passed to |
TODO
A data frame (tibble) in long format containing the ordination
scores. The first two components are score (the type of score in each
row) and label (the text label to use on plots for this row). The
remaining columns are the extracted ordination axis scores.
Gavin L. Simpson
library("vegan") data(dune) data(dune.env) sol <- rda(dune ~ A1 + Management, data = dune.env) head(fortify(sol))library("vegan") data(dune) data(dune.env) sol <- rda(dune ~ A1 + Management, data = dune.env) head(fortify(sol))
Prepares a fortified version of results from
vegan::renyiaccum() objects.
## S3 method for class 'renyiaccum' fortify(model, data, ...) ## S3 method for class 'renyiaccum' tidy(x, data, ...)## S3 method for class 'renyiaccum' fortify(model, data, ...) ## S3 method for class 'renyiaccum' tidy(x, data, ...)
model, x
|
an object of class |
data |
original data set. Currently ignored. |
... |
additional arguments passed to other methods. Ignored in this method. |
A data frame (tibble) is returned. What is returned depends on how
vegan::renyiaccum() was called.
If raw = FALSE, then a data frame with columns site, scale, mean,
std_dev, min, max, q2.5, and q97.5, containing the accumulated
sites, the Rényi scale, and summary statistics of the
Rényi accumulation curves. An additional column collector
will be present if collector = TRUE was used in the vegan::renyiaccum()
call.
If raw = TRUE, then a data frame with columns site, permutation,
scale, and diversity, containing the site and permutation
identifiers, Rényi scale, and the Rényi
diversity, respectively.
Gavin L. Simpson much rewritten from an original by Didzis Elferts.
library("vegan") library("ggplot2") data(BCI) pool <- renyiaccum(BCI) df <- fortify(pool) df ggplot(df, aes(x = site, y = mean)) + geom_ribbon(aes(ymin = q2.5, ymax = q97.5, x = site), alpha = 0.2, inherit.aes = FALSE) + geom_line() + facet_wrap(~ scale)library("vegan") library("ggplot2") data(BCI) pool <- renyiaccum(BCI) df <- fortify(pool) df ggplot(df, aes(x = site, y = mean)) + geom_ribbon(aes(ymin = q2.5, ymax = q97.5, x = site), alpha = 0.2, inherit.aes = FALSE) + geom_line() + facet_wrap(~ scale)
"vegan_pco" object.Fortifies an object of class "vegan_pco" to produce a
data frame of the selected axis scores in long format, suitable for
plotting with ggplot2::ggplot().
## S3 method for class 'vegan_pco' fortify(model, data = NULL, axes = 1:6, ...) ## S3 method for class 'vegan_pco' tidy(x, data = NULL, axes = 1:6, const = NULL, ...)## S3 method for class 'vegan_pco' fortify(model, data = NULL, axes = 1:6, ...) ## S3 method for class 'vegan_pco' tidy(x, data = NULL, axes = 1:6, const = NULL, ...)
model, x
|
an object of class |
data |
currently ignored. |
axes |
numeric; which axes to extract scores for. |
... |
additional arguments passed to |
const |
NULL; General scaling constant to RDA scores. See
|
TODO
A data frame (tibble) in long format containing the ordination
scores. The first two components are score (the type of score in each
row) and label (the text label to use on plots for this row). The
remaining columns are the extracted ordination axis scores.
Gavin L. Simpson
library("vegan") data(dune) sol <- pco(dune) head(fortify(sol))library("vegan") data(dune) sol <- pco(dune) head(fortify(sol))
Function adds layers of arrows (ggplot2::geom_segment()) and
(optionally) their text labels (ggplot2::geom_text() or
ggplot2::geom_label()) to an ordiggplot() graph. Typically
these arrows are biplot or regression scores, but the function
allows drawing species arrows for PCA biplots, or adding fitted
environmental vectors of vegan::envfit().
geom_ordi_arrow( score, data, text = TRUE, box = FALSE, arrow.mul = 1, arrow.params = list(), text.params = list(), ... )geom_ordi_arrow( score, data, text = TRUE, box = FALSE, arrow.mul = 1, arrow.params = list(), text.params = list(), ... )
score |
Ordination score to be added to the plot. |
data |
Alternative data to the function that will be used
instead of |
text |
Add text labels to the plot (logical). |
box |
Draw a non-transparent box behind the text (logical). |
arrow.mul |
Arrow multiplier when arrows end points are given
in |
arrow.params, text.params
|
Parameters to modify arrows or their text labels. |
... |
other arguments passed to |
Returns ggplot2 layers geom_segment for arrows, and
geom_text or geom_label (optionally) for their names.
Jari Oksanen
Underlying functions are ggplot2::geom_segment(),
ggplot2::geom_text() and ggplot2::geom_label().
library(vegan) data(varespec, varechem, package="vegan") ## PCA biplot mod <- rda(varespec) ordiggplot(mod, scaling = "sites", corr = TRUE) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("species") ## RDA mod <- rda(varespec ~ N + K + Al + Baresoil, varechem) ordiggplot(mod) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("biplot", box = TRUE)library(vegan) data(varespec, varechem, package="vegan") ## PCA biplot mod <- rda(varespec) ordiggplot(mod, scaling = "sites", corr = TRUE) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("species") ## RDA mod <- rda(varespec ~ N + K + Al + Baresoil, varechem) ordiggplot(mod) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("biplot", box = TRUE)
The origin (coordinates 0,0) has a special interpretation in
eigenvector methods: sites, species or variables at the centroid
are average cases, and the point is more exceptional the further it
is from the origin. Therefore crosshair of axes through the origin
should be added to the ordination graph with eigenvector
methods. Often it is forgotten, though. See the Example in
geom_ordi_arrow() where the length of PCA biplot arrow shows how
exceptional the species is in ordination.
geom_ordi_axis(lty = 3, ...)geom_ordi_axis(lty = 3, ...)
lty |
Linetype. |
... |
other arguments passed to |
Returns ggplot2 layers geom_hline and geom_vline.
Jari Oksanen
The underlying functions are ggplot2::geom_hline() and
ggplot2::geom_vline().
library(vegan) library(ggplot2) data(dune, package = "vegan") mod <- cca(dune) ## simple "autoplot" using ggplot2::geom_text ordiggplot(mod) + geom_ordi_axis() + geom_text()library(vegan) library(ggplot2) data(dune, package = "vegan") mod <- cca(dune) ## simple "autoplot" using ggplot2::geom_text ordiggplot(mod) + geom_ordi_axis() + geom_text()
Function adds “labels” or text in a box with non-transparent
background using ggplot2::geom_label() to an ordiggplot()
graph. These can help in congested plot since uppermost labels are
readable (but cover lower ones), or to emphasize text. Some
ggvegan functions call ggplot2::geom_label() with argument
box = TRUE.
geom_ordi_label(score, data, ...)geom_ordi_label(score, data, ...)
score |
Ordination score to be added to the plot. |
data |
Alternative data to the function that will be used
instead of |
... |
other arguments passed to |
Returns a ggplot2 layer geom_label.
Jari Oksanen
library(vegan) library(ggplot2) data(dune, dune.env, package = "vegan") mod <- cca(dune ~ Moisture, dune.env) ordiggplot(mod) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_label("species", size = 3, mapping = aes(fontface = "italic")) + geom_ordi_label("centroids", size = 5, mapping = aes(fontface = "bold"))library(vegan) library(ggplot2) data(dune, dune.env, package = "vegan") mod <- cca(dune ~ Moisture, dune.env) ordiggplot(mod) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_label("species", size = 3, mapping = aes(fontface = "italic")) + geom_ordi_label("centroids", size = 5, mapping = aes(fontface = "bold"))
Function adds a point layer using ggplot2::geom_point() to an
ordiggplot() graph.
geom_ordi_point(score, data, ...)geom_ordi_point(score, data, ...)
score |
Ordination score to be added to the plot. |
data |
Alternative data to the function that will be used
instead of |
... |
other arguments passed to |
Returns a ggplot2 layer geom_point.
Jari Oksanen
library(vegan) library(ggplot2) data(mite, mite.env, package = "vegan") mod <- metaMDS(mite, trace = 0) surf <- vegan::ordisurf(mod ~ WatrCont, mite.env, plot = FALSE) ef <- vegan::envfit(mod ~ WatrCont + Topo, mite.env) ## Change sizes and colours of points ordiggplot(mod) + geom_ordi_point("sites", mapping=aes(colour = mite.env$Topo, size=mite.env$WatrCont/10)) + autolayer(surf) + autolayer(ef, box = TRUE)library(vegan) library(ggplot2) data(mite, mite.env, package = "vegan") mod <- metaMDS(mite, trace = 0) surf <- vegan::ordisurf(mod ~ WatrCont, mite.env, plot = FALSE) ef <- vegan::envfit(mod ~ WatrCont + Topo, mite.env) ## Change sizes and colours of points ordiggplot(mod) + geom_ordi_point("sites", mapping=aes(colour = mite.env$Topo, size=mite.env$WatrCont/10)) + autolayer(surf) + autolayer(ef, box = TRUE)
Function adds points to the exact position of the ordination score with a label, but labels are repelled from each other to avoid over-plotting. In very congested areas, the labels are completely omitted.
geom_ordi_repel( score, data, box = FALSE, points = TRUE, point.params = list(), text.params = list(), ... )geom_ordi_repel( score, data, box = FALSE, points = TRUE, point.params = list(), text.params = list(), ... )
score |
Ordination score added to the plot. |
data |
Alternative data to the function that will be used
instead of |
box |
Draw a non-transparent box behind the text (logical). |
points |
Draw points (logical). |
point.params, text.params
|
Parameters to modify points or their repelled text labels. |
... |
other arguments passed to |
Returns ggrepel layers geom_text_repel or
geom_label_repel and ggplot2 layer geom_point (optionally).
Jari Oksanen
library(vegan) data(mite, mite.env, package = "vegan") mod <- cca(mite) ordiggplot(mod) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_repel("species", text.params = list(size=3, fontface = "italic"))library(vegan) data(mite, mite.env, package = "vegan") mod <- cca(mite) ordiggplot(mod) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_repel("species", text.params = list(size=3, fontface = "italic"))
Function adds a text layer to an ordiggplot() graph using
ggplot2::geom_text().
geom_ordi_text(score, data, ...)geom_ordi_text(score, data, ...)
score |
Ordination score to be added to the plot. |
data |
Alternative data to the function that will be used
instead of |
... |
other arguments passed to |
Returns a ggplot2 layer geom_text.
Jari Oksanen
library(vegan) library(ggplot2) data(dune, package = "vegan") mod <- metaMDS(dune, trace = 0) ordiggplot(mod) + geom_ordi_text("sites", size=3) + geom_ordi_text("species", mapping=aes(fontface="italic"))library(vegan) library(ggplot2) data(dune, package = "vegan") mod <- metaMDS(dune, trace = 0) ordiggplot(mod) + geom_ordi_text("sites", size=3) + geom_ordi_text("species", mapping=aes(fontface="italic"))
Find the character vector of names for the two dimensions of data to be plotted.
get_dimension_names(object)get_dimension_names(object)
object |
a fortified ordination object. |
A length 2 character vector of dimension names.
Gavin L. Simpson
Adds labels to a plot using one of ggplot2::geom_label(),
ggplot2::geom_text(), ggrepel::geom_label_repel() or
ggrepel::geom_text_repel().
label_fun(data, geom = c("label", "text", "label_repel", "text_repel"), vars)label_fun(data, geom = c("label", "text", "label_repel", "text_repel"), vars)
data |
data frame; data set to use for the label layer. Must contain a variable label containing the strings to use as labels. |
geom |
character; which geom to use for labelling. |
vars |
character; vector of names of variables to pass to the |
Gavin L. Simpson
List of layers to draw for a given vegan object
layer_draw_list(valid, layers = NULL, available = NULL)layer_draw_list(valid, layers = NULL, available = NULL)
valid |
character; vector of valid layer names |
layers |
character; a vector of layer names for |
available |
character; what layers are actually available |
Function ordiggplot sets up an ordination graph but draws no
result. You can add new graphical elements to this plot with
geom_ordi_* functions of this package, or you can use standard
ggplot2 geom_* functions and use ggscores as their
data argument.
ordiggplot(model, axes = c(1, 2), legend.position = "right", ...) ggscores(score)ordiggplot(model, axes = c(1, 2), legend.position = "right", ...) ggscores(score)
model |
An ordination result object with a compatible
|
axes |
Two axes to be plotted |
legend.position |
Legend position: see |
... |
Parameters passed to |
score |
Ordination score to be added to the plot. |
The ggvegan package has two contrasting approaches to draw
ordination plots. The autoplot functions (e.g. autoplot.rda(),
autoplot.cca(), and autoplot.metaMDS()) draw a complete plot
with one command, but the design is hard-coded in the
function, and it may be difficult to add new layers to the graph.
In contrast, function ordiggplot() only sets up an ordination
plot, but allows you to add layers to the graph one by one with
full flexibility of the ggplot2 functions. It initializes
the ggplot2 graph with idiom ggplot(data, mapping) which
allows other functions to use the ordination data and axis
mapping in adding new layers. The included mapping specifies
coordinates x and y and variables label for text labels and a
score-type specific colour. Any ggplot2 function that can
use this mapping will work automatically. Support function
ggscores selects a slice of ordination scores that can be used as
a data argument in the geom function. To plot the site scores
of ordination result mod as points, you can use idiom
ordiggplot(mod) + geom_point(data = ggscores("sites")).
There are specific functions to ease adding layers to an ordination
graph. See the documentation of geom_ordi_arrow(),
geom_ordi_label(), geom_ordi_point(), geom_ordi_repel(),
geom_ordi_text(). These correspond to similarly named geom_*
functions. For instance, geom_ordi_point adds very little to
geom_point, and you can use all arguments of the standard geom
function. These functions are of type geom_ordi_*(score, ...)
which is similar to geom_*(data = ggscores(score), ...). Some
functions were adapted to typical ordination data and return
compound geometries. For instance, geom_ordi_arrow() returns
layers geom_segment for the arrows, and geom_text for their
name labels. In addition, there are functions to add previously
fitted results of vegan::envfit() and vegan::ordisurf() (see
autolayer.envfit(), autolayer.ordisurf()).
The ordiggplot() function extracts results using fortify()
functions of this package, and it accepts the arguments of those
functions. This allows setting, e.g., the scaling of ordination
axes. The ordiggplot skeleton sets up data used in plotting,
and you should define axis scaling, axes etc in the ordiggplot
call and they will be used in all added layers.
Returns a ggplot object with slot data for full
ordination data and slot mapping with ordination axes mapped to
x and y, label to text labels for each row and factor
score type mapped to colour.
Jari Oksanen
geom_ordi_arrow(), geom_ordi_axis(),
geom_ordi_label(), geom_ordi_point(), geom_ordi_repel(),
geom_ordi_text(), autolayer.envfit(), autolayer.ordisurf().
library("vegan") library("ggplot2") data(dune, dune.env, varespec, varechem) m <- cca(dune ~ Management + A1, dune.env) ## data and mapping of the ordiggplot object ordiggplot(m)@data ordiggplot(m)@mapping ## use geom_ordi_* functions ordiggplot(m) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_repel("species", col = "darkblue", text.params = list(mapping = aes(fontface = "italic"))) + geom_ordi_label("centroids") + geom_ordi_arrow("biplot") ## use ggscores + standard geom_* functions ordiggplot(m, scaling = "sites") + geom_point(data = ggscores("sites")) + geom_text(data = ggscores("species"), mapping = aes(fontface = "italic")) + geom_label(data = ggscores("centroids"), fill = "yellow") + geom_ordi_arrow("biplot") ## Messy arrow biplot for PCA m <- rda(dune) ordiggplot(m, corr = TRUE) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("species")library("vegan") library("ggplot2") data(dune, dune.env, varespec, varechem) m <- cca(dune ~ Management + A1, dune.env) ## data and mapping of the ordiggplot object ordiggplot(m)@data ordiggplot(m)@mapping ## use geom_ordi_* functions ordiggplot(m) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_repel("species", col = "darkblue", text.params = list(mapping = aes(fontface = "italic"))) + geom_ordi_label("centroids") + geom_ordi_arrow("biplot") ## use ggscores + standard geom_* functions ordiggplot(m, scaling = "sites") + geom_point(data = ggscores("sites")) + geom_text(data = ggscores("species"), mapping = aes(fontface = "italic")) + geom_label(data = ggscores("centroids"), fill = "yellow") + geom_ordi_arrow("biplot") ## Messy arrow biplot for PCA m <- rda(dune) ordiggplot(m, corr = TRUE) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("species")
Returns the number of scores returns in object 'x“.
scores_length(x)scores_length(x)
x |
The object whose number of scores is required. |
a numeric vector of length 1 with the number of scores.
Gavin L. Simpson
Fits arrows to show the direction of fastest increase
in continuous environmental variables in ordination space.The
arrows are scaled relative to their correlation coefficient,
and they can be added to an ordination plot with geom_ordi_arrow().
The arrows are fitted to the data and mapping of
ordiggplot(), and they will adapt to changes in the parameters
of ordiggplot(). This is in contrast to similar
autolayer.envfit() command or to
geom_ordi_arrow(data=<envfit-object>) which will use a
previously fitted <envfit-object> and will not not change if the
ordiggplot() definitions change.
stat_vectorfit( mapping = NULL, data = NULL, geom = "text", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, edata = NULL, formula = NULL, arrow.mul = NULL, ... )stat_vectorfit( mapping = NULL, data = NULL, geom = "text", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, edata = NULL, formula = NULL, arrow.mul = NULL, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
Remove missing values (Not Yet Implemented). |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
edata |
Environmental data where the continuous variables are found. |
formula |
Formula to select variables from |
arrow.mul |
Multiplier to arrow length. If missing, the multiplier is selected automatically so that arrows fit the current graph. |
... |
Other arguments passed to the functions. |
Returns a layer that containts a StatVectorfit object that is responsible for rendering the fitted vectors in the plot.
Jari Oksanen
library("vegan") library("ggplot2") data(mite, mite.env) m <- metaMDS(mite, trace = FALSE, trymax = 100) ## add fitted vectors for continuous variables ordiggplot(m) + geom_ordi_point("sites") + geom_ordi_arrow("sites", stat = "vectorfit", edata = mite.env) ## can be faceted ordiggplot(m) + geom_ordi_point("sites") + geom_ordi_arrow("sites", stat = "vectorfit", edata = mite.env) + facet_wrap(mite.env$Topo)library("vegan") library("ggplot2") data(mite, mite.env) m <- metaMDS(mite, trace = FALSE, trymax = 100) ## add fitted vectors for continuous variables ordiggplot(m) + geom_ordi_point("sites") + geom_ordi_arrow("sites", stat = "vectorfit", edata = mite.env) ## can be faceted ordiggplot(m) + geom_ordi_point("sites") + geom_ordi_arrow("sites", stat = "vectorfit", edata = mite.env) + facet_wrap(mite.env$Topo)
Valid layers for vegan objects
valid_layers(object, ...) ## S3 method for class 'rda' valid_layers(object, ...) ## S3 method for class 'cca' valid_layers(object, ...) ## S3 method for class 'dbrda' valid_layers(object, ...)valid_layers(object, ...) ## S3 method for class 'rda' valid_layers(object, ...) ## S3 method for class 'cca' valid_layers(object, ...) ## S3 method for class 'dbrda' valid_layers(object, ...)
object |
An R object. |
... |
Additional arguments passed to methods. |
A character vector of valid ordination layers for the provided
object.