Title: | 'ggplot2' Plots for the 'vegan' Package |
---|---|
Description: | Functions to produce ggplot2-based plots of objects produced by functions in the vegan package. |
Authors: | Gavin L. Simpson [aut, cre], Jari Oksanen [aut], Didzis Elferts [ctb] |
Maintainer: | Gavin L. Simpson <[email protected]> |
License: | GPL-2 |
Version: | 0.1.999 |
Built: | 2024-10-29 03:00:31 UTC |
Source: | https://github.com/gavinsimpson/ggvegan |
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 geoms will be used ofr 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
"anosim"
Produces a multi-layer ggplot object representing the output of objects produced by 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.
data(dune) data(dune.env) dune.dist <- vegdist(dune) dune.ano <- with(dune.env, anosim(dune.dist, Management)) autoplot(dune.ano, notch = FALSE)
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 cca
, or 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, xlab, ... )
## 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, xlab, ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geoms to use for the layers. Can be a
vector of length equal to |
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
data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) autoplot(sol)
data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) autoplot(sol)
"decorana"
Produces a multi-layer ggplot object representing the output of objects produced by decorana
.
## S3 method for class 'decorana' autoplot( object, axes = c(1, 2), geom = c("point", "text"), layers = c("species", "sites"), 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("species", "sites"), 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 geoms to use for the layers. Can be a
vector of length equal to |
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
data(dune) sol <- decorana(dune) autoplot(sol) autoplot(sol, display = "species", geom = "text")
data(dune) sol <- decorana(dune) autoplot(sol) autoplot(sol, display = "species", geom = "text")
envfit
objectsProduces a multi-layer ggplot object representing the output of objects produced by isomap
.
## 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
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)
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", size = 1, 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", size = 1, 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. |
size |
numeric; size 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
data(BCI) mod <- fisherfit(BCI[5,]) autoplot(mod)
data(BCI) mod <- fisherfit(BCI[5,]) autoplot(mod)
"isomap"
Produces a multi-layer ggplot object representing the output of objects produced by isomap
.
## S3 method for class 'isomap' autoplot( object, axes = c(1, 2), geom = c("point", "text"), network = TRUE, line.col = "grey85", size = 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", size = 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. |
size |
numeric; size 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
data(BCI) dis <- vegdist(BCI) ord <- isomap(dis, k = 3) autoplot(ord) autoplot(ord, geom = "text")
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 metaMDS
.
## S3 method for class 'metaMDS' autoplot( object, axes = c(1, 2), 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, axes = c(1, 2), geom = c("point", "text"), layers = c("species", "sites"), 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 geoms to use for the layers. Can be a
vector of length equal to |
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
## load example data data(dune) sol <- metaMDS(dune) autoplot(sol)
## load example data data(dune) sol <- metaMDS(dune) autoplot(sol)
"poolaccum"
Produces a multi-layer ggplot object representing the output of objects
produced by 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 facetting the plot, how many columns to use. Default arguuments 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
data(BCI) pool <- poolaccum(BCI) autoplot(pool) ## Turn off facetting; turns off ribbon too autoplot(pool, facet = FALSE)
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 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
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) autoplot(mod, select = want)
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) autoplot(mod, select = want)
Draws a bar plot of species rank abundance with Fisher's log-series 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", size = 1, ... )
## 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", size = 1, ... )
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, |
bar.fill |
fill colour for the bars. |
line.col |
colour for Fisher's log-series curve. |
size |
numeric; size aesthetic for the log-series curve. |
... |
additional arguments passed to other methods. |
A ggplot object.
Gavin L. Simpson
data(BCI) pfit <- prestonfit(colSums(BCI)) autoplot(pfit)
data(BCI) pfit <- prestonfit(colSums(BCI)) autoplot(pfit)
'rda'
Produces a multi-layer ggplot object representing the output of objects produced by 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 = "right", title = NULL, subtitle = NULL, caption = NULL, ylab, xlab, const, ... )
## 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 = "right", title = NULL, subtitle = NULL, caption = NULL, ylab, xlab, const, ... )
object |
an object of class |
axes |
numeric; which axes to plot, given as a vector of length 2. |
geom |
character; which geoms to use for the layers. Can be a vector of
up to length 2, in which case, the first element of |
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 |
... |
Additional arguments passed to |
TODO
Returns a ggplot object.
Gavin L. Simpson
data(dune) pca <- rda(dune) autoplot(pca) ## Just the species scores autoplot(pca, layers = "species")
data(dune) pca <- rda(dune) autoplot(pca) ## Just the species scores autoplot(pca, layers = "species")
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 anosim
objects.
## S3 method for class 'anosim' fortify(model, data, ...)
## S3 method for class 'anosim' fortify(model, data, ...)
model |
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.
Didzis Elferts
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)
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 ggplot
.
## S3 method for class 'cca' fortify( model, data, axes = 1:6, display = c("sp", "wa", "lc", "bp", "cn"), ... )
## S3 method for class 'cca' fortify( model, data, axes = 1:6, display = c("sp", "wa", "lc", "bp", "cn"), ... )
model |
an object of class |
data |
currently ignored. |
axes |
numeric; which axes to extract scores for. |
display |
numeric; 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
data(dune) data(dune.env) sol <- cca(dune ~ A1 + Management, data = dune.env) head(fortify(sol))
data(dune) data(dune.env) sol <- cca(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 ggplot
.
## S3 method for class 'decorana' fortify(model, data, axes = 1:4, display = c("sites", "species"), ...)
## S3 method for class 'decorana' fortify(model, data, axes = 1:4, display = c("sites", "species"), ...)
model |
an object of class |
data |
currently ignored. |
axes |
numeric; which axis scores are required? |
display |
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
data(dune) sol <- decorana(dune) head(fortify(sol)) head(fortify(sol, display = "species"))
data(dune) sol <- decorana(dune) head(fortify(sol)) head(fortify(sol, display = "species"))
envfit
objectsProduces a tidy data frame from the results of an envfit
object.
## S3 method for class 'envfit' fortify(model, data, ...)
## S3 method for class 'envfit' fortify(model, data, ...)
model |
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 scores.envfit
.
Gavin L. Simpson
data(varespec, varechem) ord <- metaMDS(varespec) fit <- envfit(ord, varechem, perm = 199) fortify(fit) data(dune, dune.env) ord <- cca(dune) fit <- envfit(ord ~ Moisture + A1, dune.env, perm = 199) fortify(fit)
data(varespec, varechem) ord <- metaMDS(varespec) fit <- envfit(ord, varechem, perm = 199) fortify(fit) data(dune, dune.env) ord <- cca(dune) fit <- envfit(ord ~ Moisture + A1, dune.env, perm = 199) fortify(fit)
Prepares a data frame of results from a fisherfit
object suitable for plotting with ggplot
.
## S3 method for class 'fisherfit' fortify(model, data, ...)
## S3 method for class 'fisherfit' fortify(model, data, ...)
model |
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
data(BCI) mod <- fisherfit(BCI[5,]) head(fortify(mod))
data(BCI) mod <- fisherfit(BCI[5,]) head(fortify(mod))
Prepares fortified versions of results from isomap
objects.
## S3 method for class 'isomap' fortify(model, data = NULL, axes = 1:6, what = c("sites", "network"), ...)
## S3 method for class 'isomap' fortify(model, data = NULL, axes = 1:6, what = c("sites", "network"), ...)
model |
an object of class |
data |
data.frame; additonal data to be added to the forified 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 isomap
object. The first is the standard scores representation of fortified ordinations in vegan, which results in a wide data frame where rows cotain observations and columne 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 adidtional variable is label
, containing a label for each observation. For what = "network"
, the data frame contains four variables cotaining the coordinates in the chosen MDS axes for the start and end points of the network edges.
Gavin L. Simpson
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()
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 ggplot
.
## S3 method for class 'metaMDS' fortify(model, data, ...)
## S3 method for class 'metaMDS' fortify(model, data, ...)
model |
an object of class |
data |
currently ignored. |
... |
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
## load example data data(dune) ord <- metaMDS(dune) head(fortify(ord))
## load example data data(dune) ord <- metaMDS(dune) head(fortify(ord))
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' fortify(model, data, alpha = 0.05, ...)
model |
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.
Didzis Elferts & Gavin L. Simpson
data(BCI) pool <- poolaccum(BCI) df <- fortify(pool) 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)
data(BCI) pool <- poolaccum(BCI) df <- fortify(pool) 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 ggplot
.
## S3 method for class 'prc' fortify(model, data, scaling = 3, axis = 1, ...)
## S3 method for class 'prc' fortify(model, data, scaling = 3, axis = 1, ...)
model |
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 indictor factor and a label for the rows for use
in plotting.
Gavin L. Simpson
Prepares a data frame of results from a fisherfit
object suitable for plotting with ggplot
.
## S3 method for class 'prestonfit' fortify(model, data, ...)
## S3 method for class 'prestonfit' fortify(model, data, ...)
model |
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
data(BCI) pfit <- prestonfit(colSums(BCI)) head(fortify(pfit))
data(BCI) pfit <- prestonfit(colSums(BCI)) head(fortify(pfit))
Add a biplot arrow layer to an ordiggplot
geom_ordi_arrow( score, data, text = TRUE, box = FALSE, arrow.params = list(), text.params = list(), ... )
geom_ordi_arrow( score, data, text = TRUE, box = FALSE, 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. |
box |
Draw a box behind the text (logical). |
arrow.params , text.params
|
Parameters to modify arrows or their text labels. |
... |
other arguments passed to |
Crosshair for axes in eigenvector methods
geom_ordi_axis(lty = 3, ...)
geom_ordi_axis(lty = 3, ...)
lty |
Linetype. |
... |
other arguments passed to |
Add a label layer to an ordiggplot
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 |
Add a point layer to an ordiggplot
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 |
Add a text layer to an ordiggplot
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 |
Find the character vector of names for the two dimensions of data to be plotted.
getDimensionNames(object)
getDimensionNames(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 geom_label
, geom_text
, geom_label_repel
or 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 |
geom |
character; which geom to use for labelling. |
vars |
character; vector of names of variables to ass 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 |
charecter; 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_*
function of this package, or you can use standard
ggplot2 geom_*
functions and use ggscores
as their data
argument.
ordiggplot(model, axes = c(1, 2), arrowmul, ...) ggscores(score)
ordiggplot(model, axes = c(1, 2), arrowmul, ...) ggscores(score)
model |
An ordination result object from vegan. |
axes |
Two axes to be plotted |
arrowmul |
Multiplier to arrow length. If missing, the arrow length are adjusted to fit to other scores, but if some score types are not displayed, the arrows may be badly scaled, and manual adjustment can be useful. |
... |
Parameters passed to underlying functions. |
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. However, you
can add new elements to the graph.
In contrast, function ordiggplot()
only sets up an ordination
plot, and does not draw anything. It allows you to add layers to the plot
one by one with full flexibility of the ggplot2 functions.
There are some specific functions geom_ordi_*
functions that are similar as similarly named geom_*
functions. For these you need to give the type of ordination scores
to be added, and in addition, you can give any geom_*
function arguments to modify the plot. Alternatively, you can use
any ggplot2 function and in its data
argument use
ggscores()
function to select the data elements for the
function.
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.
library("vegan") data(dune, dune.env, varespec, varechem) m <- cca(dune ~ Management + A1, dune.env) ## use geom_ordi_* functions ordiggplot(m) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_text("species", col = "darkblue", 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) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("species") ## Fitted vectors, selecting variables with formula m <- metaMDS(varespec, trace = FALSE) ## plot ordiggplot(m) + geom_ordi_point("sites") + geom_ordi_arrow("sites", stat = "vectorfit", edata = varechem, formula = ~ N + Ca + Al + Humdepth + pH)
library("vegan") data(dune, dune.env, varespec, varechem) m <- cca(dune ~ Management + A1, dune.env) ## use geom_ordi_* functions ordiggplot(m) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_text("species", col = "darkblue", 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) + geom_ordi_axis() + geom_ordi_point("sites") + geom_ordi_arrow("species") ## Fitted vectors, selecting variables with formula m <- metaMDS(varespec, trace = FALSE) ## plot ordiggplot(m) + geom_ordi_point("sites") + geom_ordi_arrow("sites", stat = "vectorfit", edata = varechem, formula = ~ N + Ca + Al + Humdepth + pH)
Returns the number of scores returns in object x
.
scoresLength(x)
scoresLength(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()
.
stat_vectorfit( mapping = NULL, data = NULL, geom = "text", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, edata = NULL, formula = NULL, arrowmul = NULL, ... )
stat_vectorfit( mapping = NULL, data = NULL, geom = "text", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, edata = NULL, formula = NULL, arrowmul = 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, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
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 |
arrowmul |
Multiplier to arrow length. If missing, the multiplier is selected automatically so that arrows fit the current graph. |
... |
Other arguments passed to the functions. |
library("vegan") 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") 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, ...)
valid_layers(object, ...) ## S3 method for class 'rda' valid_layers(object, ...) ## S3 method for class 'cca' valid_layers(object, ...)
object |
An R object. |
... |
Additional arguments passed to methods. |