Package 'ggvegan'

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

Help Index


Adds species and site score layers to an existing plot

Description

Adds species and site score layers to an existing plot

Usage

add_spp_site_scores(object, plt, vars, geom, draw_list, arrows)

Arguments

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 Vectors to Data

Description

Scale vector arrows to fill proportion of the data.

Usage

arrow_mul(arrows, data, at = c(0, 0), fill = 0.75)

Arguments

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

Value

a numeric multiplier that will scale the arrows

Author(s)

Gavin L. Simpson


ggplot-based plot for objects of class "anosim"

Description

Produces a multi-layer ggplot object representing the output of objects produced by anosim.

Usage

## 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)),
  ...
)

Arguments

object

an object of class "anosim", the result of a call to anosim.

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.

Value

A ggplot object.

Author(s)

Didzis Elferts. Modifications by Gavin L. Simpson.

Examples

data(dune)
data(dune.env)
dune.dist <- vegdist(dune)
dune.ano <- with(dune.env, anosim(dune.dist, Management))

autoplot(dune.ano, notch = FALSE)

ggplot-based plot for objects of class "cca"

Description

Produces a multi-layer ggplot object representing the output of objects produced by cca, or capscale.

Usage

## 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,
  ...
)

Arguments

object

an object of class "cca", the result of a call to cca or capscale.

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 length(display), in which case the ith element of type refers to the ith element of display.

layers

character; which scores to plot as layers

legend.position

character or two-element numeric vector; where to position the legend. See theme for details. Use "none" to not draw the legend.

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 fortify.cca.

Details

TODO

Value

Returns a ggplot object.

Author(s)

Gavin L. Simpson

Examples

data(dune)
data(dune.env)

sol <- cca(dune ~ A1 + Management, data = dune.env)
autoplot(sol)

ggplot-based plot for objects of class "decorana"

Description

Produces a multi-layer ggplot object representing the output of objects produced by decorana.

Usage

## 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,
  ...
)

Arguments

object

an object of class "decorana", the result of a call to decorana.

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 length(display), in which case the ith element of type refers to the ith element of display.

layers

character; which scores to plot as layers

legend.position

character or two-element numeric vector; where to position the legend. See theme for details. Use "none" to not draw the legend.

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 fortify.decorana.

Details

TODO

Value

Returns a ggplot object.

Author(s)

Gavin L. Simpson

Examples

data(dune)

sol <- decorana(dune)
autoplot(sol)
autoplot(sol, display = "species", geom = "text")

ggplot-based plot for envfit objects

Description

Produces a multi-layer ggplot object representing the output of objects produced by isomap.

Usage

## 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,
  ...
)

Arguments

object

an object of class "envfit", the result of a call to envfit.

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 fortify.

Value

A ggplot object.

Author(s)

Gavin L. Simpson

Examples

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)

Plot Fisher's log-series

Description

Draws a bar plot of species rank abundance with Fisher's log-series superimposed.

Usage

## 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,
  ...
)

Arguments

object

an object of class fisherfit.

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, NA, does not draw outlines around bars.

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.

Value

A ggplot object.

Author(s)

Gavin L. Simpson

Examples

data(BCI)
mod <- fisherfit(BCI[5,])
autoplot(mod)

ggplot-based plot for objects of class "isomap"

Description

Produces a multi-layer ggplot object representing the output of objects produced by isomap.

Usage

## 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,
  ...
)

Arguments

object

an object of class "isomap", the result of a call to isomap.

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.

Value

A ggplot object.

Author(s)

Gavin L. Simpson

Examples

data(BCI)
dis <- vegdist(BCI)
ord <- isomap(dis, k = 3)

autoplot(ord)

autoplot(ord, geom = "text")

ggplot-based plot for objects of class "metaMDS"

Description

Produces a multi-layer ggplot object representing the output of objects produced by metaMDS.

Usage

## 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,
  ...
)

Arguments

object

an object of class "metaMDS", the result of a call to metaMDS.

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 length(display), in which case the ith element of type refers to the ith element of display.

layers

character; which scores to plot as layers

legend.position

character or two-element numeric vector; where to position the legend. See theme for details. Use "none" to not draw the legend.

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 fortify.metaMDS.

Details

TODO

Value

Returns a ggplot object.

Author(s)

Gavin L. Simpson

Examples

## load example data
data(dune)

sol <- metaMDS(dune)
autoplot(sol)

ggplot-based plot for objects of class "poolaccum"

Description

Produces a multi-layer ggplot object representing the output of objects produced by poolaccum.

Usage

## 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,
  ...
)

Arguments

object

an object of class "poolaccum", the result of a call to poolaccum.

facet

logical; should extrapolated richness estimators be shown in separate facets?

ribbon

logical; show the quantile-based uncertainty interval? Uses geom_ribbon for plot.

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 alpha aesthetic of ggplot2::geom_ribbon().

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 fortify.poolaccum().

Value

A ggplot object.

Author(s)

Didzis Elferts & Gavin L. Simpson

Examples

data(BCI)
pool <- poolaccum(BCI)

autoplot(pool)

## Turn off facetting; turns off ribbon too
autoplot(pool, facet = FALSE)

ggplot-based plot for objects of class "prc"

Description

Produces a multi-layer ggplot object representing the output of objects produced by prc.

Usage

## S3 method for class 'prc'
autoplot(
  object,
  select,
  xlab,
  ylab,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  legend.position = "top",
  ...
)

Arguments

object

an object inheriting from class "prc", the result of a call to prc.

select

a logical vector where TRUE selects and FALSE deselects species. Alternatively a numeric vector that contains the indices selecting species. Note that these are with respect to the original species matrix, not the fortified object.

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 legend.position in function theme.

...

Additional arguments passed to fortify.prc.

Details

TODO

Value

Returns a ggplot object.

Author(s)

Gavin L. Simpson

Examples

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)

Plot Preston's log-normal model of species abundance

Description

Draws a bar plot of species rank abundance with Fisher's log-series superimposed.

Usage

## 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,
  ...
)

Arguments

object

an object of class prestonfit.

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 Fisher's log-series curve.

size

numeric; size aesthetic for the log-series curve.

...

additional arguments passed to other methods.

Value

A ggplot object.

Author(s)

Gavin L. Simpson

Examples

data(BCI)
pfit <- prestonfit(colSums(BCI))
autoplot(pfit)

ggplot-based plot for objects of class 'rda'

Description

Produces a multi-layer ggplot object representing the output of objects produced by rda.

Usage

## 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,
  ...
)

Arguments

object

an object of class "rda", the result of a call to rda

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 geom will be used for any site scores (both weighted sum or linear combination scores), and the second element will be used for species scores. The latter will be ignored if arrows = TRUE.

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 theme for details. Use "none" to not draw the legend.

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 rda scores. See scores.rda for details.

...

Additional arguments passed to fortify.cca.

Details

TODO

Value

Returns a ggplot object.

Author(s)

Gavin L. Simpson

Examples

data(dune)

pca <- rda(dune)
autoplot(pca)

## Just the species scores
autoplot(pca, layers = "species")

Check user-supplied layers against list of valid layers

Description

Check user-supplied layers against list of valid layers

Usage

check_user_layers(user, valid, message = FALSE)

Arguments

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.


Fortify analysis of similarities (ANOSIM) results

Description

Prepares a fortified version of results from anosim objects.

Usage

## S3 method for class 'anosim'
fortify(model, data, ...)

Arguments

model

an object of class anosim.

data

original data set. Currently ignored.

...

additional arguments for other methods. Currently ignored.

Value

A data frame with columns Rank and Class with ranks of dissimilarity.

Author(s)

Didzis Elferts

Examples

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)

Fortify a "cca" object.

Description

Fortifies an object of class "cca" to produce a data frame of the selected axis scores in long format, suitable for plotting with ggplot.

Usage

## S3 method for class 'cca'
fortify(
  model,
  data,
  axes = 1:6,
  display = c("sp", "wa", "lc", "bp", "cn"),
  ...
)

Arguments

model

an object of class "cca", the result of a call to cca, rda, or capscale.

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 scores.cca, and scores.rda.

Details

TODO

Value

A data frame in long format containing the ordination scores. The first two components are the axis scores.

Author(s)

Gavin L. Simpson

Examples

data(dune)
data(dune.env)

sol <- cca(dune ~ A1 + Management, data = dune.env)
head(fortify(sol))

Fortify a "decorana" object.

Description

Fortifies an object of class "decorana" to produce a data frame of the selected axis scores in long format, suitable for plotting with ggplot.

Usage

## S3 method for class 'decorana'
fortify(model, data, axes = 1:4, display = c("sites", "species"), ...)

Arguments

model

an object of class "decorana", the result of a call to decorana.

data

currently ignored.

axes

numeric; which axis scores are required?

display

character; the scores to extract in the fortified object.

...

additional arguments passed to scores.decorana.

Details

TODO

Value

A data frame in long format containing the ordination scores. The first two components are the axis scores.

Author(s)

Gavin L. Simpson

Examples

data(dune)

sol <- decorana(dune)
head(fortify(sol))
head(fortify(sol, display = "species"))

Fortify method for envfit objects

Description

Produces a tidy data frame from the results of an envfit object.

Usage

## S3 method for class 'envfit'
fortify(model, data, ...)

Arguments

model

an object of class envfit, the result of a call to envfit.

data

additional data to augment the envfit results. Currently ignored.

...

arguments passed to scores.envfit.

Value

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.

Author(s)

Gavin L. Simpson

Examples

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)

Tidied species rank abundance data and estimated Fisher's log-series

Description

Prepares a data frame of results from a fisherfit object suitable for plotting with ggplot.

Usage

## S3 method for class 'fisherfit'
fortify(model, data, ...)

Arguments

model

an object of class fisherfit

data

original data set. Currently ignored.

...

other arguments pass to methods. Currently ignored.

Value

A data frame with columns 'Rank' and 'Abundance'. Additionally, Fisher's α\alpha and the nuisance parameter are returned as attributes 'alpha' and 'k' respectively.

Author(s)

Gavin L. Simpson

Examples

data(BCI)
mod <- fisherfit(BCI[5,])
head(fortify(mod))

Fortify isometric feature mapping results

Description

Prepares fortified versions of results from isomap objects.

Usage

## S3 method for class 'isomap'
fortify(model, data = NULL, axes = 1:6, what = c("sites", "network"), ...)

Arguments

model

an object of class isomap.

data

data.frame; additonal data to be added to the forified object.

axes

numeric; which axes to return. For what = "network" this must be of length two only.

what

character; what aspect of the results should be fortified? "sites" returns to ordination scores from the multidimensional scaling part of the model. "network" returns the coordinates for edges joining points.

...

additional arguments for other methods. Currently ignored.

Details

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".

Value

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.

Author(s)

Gavin L. Simpson

Examples

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()

Fortify a "mataMDS" object.

Description

Fortifies an object of class "metaMDS" to produce a data frame of the selected axis scores in long format, suitable for plotting with ggplot.

Usage

## S3 method for class 'metaMDS'
fortify(model, data, ...)

Arguments

model

an object of class "metaMDS", the result of a call to metaMDS.

data

currently ignored.

...

additional arguments passed to scores.metaMDS. Note you can't use display.

Details

TODO

Value

A data frame in long format containing the ordination scores. The first two components are the axis scores.

Author(s)

Gavin L. Simpson

Examples

## load example data
data(dune)

ord <- metaMDS(dune)
head(fortify(ord))

Fortify extrapolated species richness of a species pool

Description

Prepares a fortified version of results from vegan::poolaccum() objects.

Usage

## S3 method for class 'poolaccum'
fortify(model, data, alpha = 0.05, ...)

Arguments

model

an object of class vegan::poolaccum().

data

original data set. Currently ignored.

alpha

level of quantiles for envelopes shown (default 0.05).

...

additional arguments passed to vegan::summary.poolaccum(), notably display to control which indices should be computed.

Value

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 1α1 - \alpha quantile interval, and standard deviation of permutation estimates, respectively.

Author(s)

Didzis Elferts & Gavin L. Simpson

Examples

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)

Fortify a "prc" object

Description

Fortifies an object of class "prc" to produce a data frame of the selected axis scores in long format, suitable for plotting with ggplot.

Usage

## S3 method for class 'prc'
fortify(model, data, scaling = 3, axis = 1, ...)

Arguments

model

an object of class "prc", the result of a call to prc.

data

currently ignored.

scaling

the desired scaling. See scores.cca for details.

axis

numeric; which PRC axis to extract. Default is axis = 1, which is the most generally useful choice.

...

additional arguments currently ignored.

Details

TODO

Value

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.

Author(s)

Gavin L. Simpson


Tidied species octave abundance data

Description

Prepares a data frame of results from a fisherfit object suitable for plotting with ggplot.

Usage

## S3 method for class 'prestonfit'
fortify(model, data, ...)

Arguments

model

an object of class prestonfit

data

original data set. Currently ignored.

...

other arguments pass to methods. Currently ignored.

Value

A data frame with columns 'Octave' and 'Abundance'.

Author(s)

Gavin L. Simpson

Examples

data(BCI)
pfit <- prestonfit(colSums(BCI))
head(fortify(pfit))

Add a biplot arrow layer to an ordiggplot

Description

Add a biplot arrow layer to an ordiggplot

Usage

geom_ordi_arrow(
  score,
  data,
  text = TRUE,
  box = FALSE,
  arrow.params = list(),
  text.params = list(),
  ...
)

Arguments

score

Ordination score to be added to the plot.

data

Alternative data to the function that will be used instead of score.

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 ggplot2::geom_segment(), ggplot2::geom_label(), or ggplot2::geom_text()


Crosshair for axes in eigenvector methods

Description

Crosshair for axes in eigenvector methods

Usage

geom_ordi_axis(lty = 3, ...)

Arguments

lty

Linetype.

...

other arguments passed to ggplot2::geom_hline() and ggplot2::geom_vline()


Add a label layer to an ordiggplot

Description

Add a label layer to an ordiggplot

Usage

geom_ordi_label(score, data, ...)

Arguments

score

Ordination score to be added to the plot.

data

Alternative data to the function that will be used instead of score.

...

other arguments passed to ggplot2::geom_label()


Add a point layer to an ordiggplot

Description

Add a point layer to an ordiggplot

Usage

geom_ordi_point(score, data, ...)

Arguments

score

Ordination score to be added to the plot.

data

Alternative data to the function that will be used instead of score.

...

other arguments passed to ggplot2::geom_point()


Add a text layer to an ordiggplot

Description

Add a text layer to an ordiggplot

Usage

geom_ordi_text(score, data, ...)

Arguments

score

Ordination score to be added to the plot.

data

Alternative data to the function that will be used instead of score.

...

other arguments passed to ggplot2::geom_text()


Extract the names of the dimensions to plot as a character vector

Description

Find the character vector of names for the two dimensions of data to be plotted.

Usage

getDimensionNames(object)

Arguments

object

a fortified ordination object.

Value

A length 2 character vector of dimension names.

Author(s)

Gavin L. Simpson


Adds a label layer using one of a set of common geoms

Description

Adds labels to a plot using one of geom_label, geom_text, geom_label_repel or geom_text_repel.

Usage

label_fun(data, geom = c("label", "text", "label_repel", "text_repel"), vars)

Arguments

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 ass to the x and y aesthetics of the chosen geom.

Author(s)

Gavin L. Simpson


List of layers to draw for a given vegan object

Description

List of layers to draw for a given vegan object

Usage

layer_draw_list(valid, layers = NULL, available = NULL)

Arguments

valid

character; vector of valid layer names

layers

character; a vector of layer names for object that has already been filtered for validity.

available

charecter; what layers are actually available


Create a ggplot Object

Description

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.

Usage

ordiggplot(model, axes = c(1, 2), arrowmul, ...)

ggscores(score)

Arguments

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.

Details

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.

Examples

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)

Number of scores

Description

Returns the number of scores returns in object x.

Usage

scoresLength(x)

Arguments

x

The object whose number of scores is required.

Value

a numeric vector of length 1 with the number of scores.

Author(s)

Gavin L. Simpson


Add Fitted Vectors to Ordination plots

Description

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().

Usage

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,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.

na.rm

Remove missing values (Not Yet Implemented).

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

edata

Environmental data where the continuous variables are found.

formula

Formula to select variables from edata. If missing, all continuos variables of edata are used.

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.

Examples

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

Description

Valid layers for vegan objects

Usage

valid_layers(object, ...)

## S3 method for class 'rda'
valid_layers(object, ...)

## S3 method for class 'cca'
valid_layers(object, ...)

Arguments

object

An R object.

...

Additional arguments passed to methods.