Type: | Package |
Title: | Make 'ggplot2' Versions of Vegan's Ordiplots |
Version: | 0.4.3 |
Maintainer: | John Quensen <quensenj@msu.edu> |
Description: | The 'vegan' package includes several functions for adding features to ordination plots: ordiarrows(), ordiellipse(), ordihull(), ordispider() and ordisurf(). This package adds these same features to ordination plots made with 'ggplot2'. In addition, gg_ordibubble() sizes points relative to the value of an environmental variable. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Encoding: | UTF-8 |
Depends: | R (≥ 3.2.0), ggplot2 (≥ 3.0.0), vegan (≥ 2.5-2), glue |
Suggests: | formatR, permute, lattice, knitr, rmarkdown |
VignetteBuilder: | knitr |
URL: | https://github.com/jfq3/ggordiplots |
BugReports: | https://github.com/jfq3/ggordiplots/issues |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2024-01-14 15:51:25 UTC; johnq |
Author: | John Quensen |
Repository: | CRAN |
Date/Publication: | 2024-01-14 16:10:02 UTC |
ggordiplots: Make ggplots with ordiplot-type features.
Description
The vegan and BiodiversityR packages include several functions for adding features to ordination plots: ordiarrows, ordibubbles, ordiellipse, ordihull, ordispider, ordisurf, ordicluster. This package adds these same features to ordination plots made with ggplot2.
Functions
gg_enfit Fits vectors representing environmental variables to ordination plots.
gg_ordibubble Sizes site symbols in proportion to environmental variable.
gg_ordicluster Overlays cluster diagram on ordination plot.
gg_ordiplot Ordination plot with options for ellipses, hulls, and spiders distinguishing treatment groups.
gg_ordisurf Ordination plot with surface contours for environmental variable.
Vegan envfit plot
Description
Fits environmental parameters to an ordination plot of sites and plots them as arrows.
Usage
gg_envfit(
ord,
env,
groups = NA,
scaling = 1,
choices = c(1, 2),
perm = 999,
alpha = 0.05,
angle = 20,
len = 0.5,
unit = "cm",
arrow.col = "red",
pt.size = 3,
plot = TRUE
)
Arguments
ord |
An ordination object. |
env |
A data frame of environmental parameters. |
groups |
A vector of groups. |
scaling |
Scaling value for plot. |
choices |
Axes to plot. |
perm |
Number of permutations. |
alpha |
Maximum alpha value to be included in plot. |
angle |
Angle of arrow tips. |
len |
Arrow tip length. |
unit |
Unit for length ("cm", "in") |
arrow.col |
Arrow color. |
pt.size |
Symbol size. |
plot |
A logical for plotting; defaults to TRUE. |
Value
Silently returns the plot and data frames used for the plotting if the fit of any variable is significant at alpha. Otherwise returns a message that no variable is significant.
Note
In order for the arrow tips to be labeled with the names of the variables, they must be supplied as a matrix or data frame. If a single variable is supplied as a vector, the arrow tip will be labeled with "1". A way-around is to convert the vector to a data frame with the column named for the variable.
Examples
data("varespec")
data("varechem")
vare.dist <- vegdist(varespec)
vare.mds <- monoMDS(vare.dist)
gg_envfit(ord=vare.mds, env=varechem)
data("dune")
data("dune.env")
dune.dist <- vegdist(dune)
dune.mds <- monoMDS(dune.dist)
# A1 supplied as a vector
gg_envfit(dune.mds, env=dune.env$A1, groups=dune.env$Management)
# A1 supplied as a data frame
A1 <- as.data.frame(dune.env$A1)
colnames(A1) <- "A1"
gg_envfit(dune.mds, env=A1, groups=dune.env$Management)
Ordination Bubble Plot
Description
Makes a simple ordination plot of site with the symbol size scaled to an environmental variable. Result is similar to that of BiodiversityR's ordibubble function.
Usage
gg_ordibubble(
ord,
env.var,
groups = NA,
var.label = "Level",
choices = c(1, 2),
plot = TRUE
)
Arguments
ord |
An ordination object |
env.var |
An environmental variable. |
groups |
A vector of groups (optional). |
var.label |
Label for the legend; default is "Level." |
choices |
Axes to be plotted. |
plot |
A logical for plotting; defaults to TRUE. |
Value
Silently returns the plot and data frames used for the plotting.
Examples
data(dune)
data(dune.env)
dune.bray <- vegdist(dune, method = "bray")
ord <- cmdscale(dune.bray, k=(nrow(dune)-1), eig=TRUE, add=TRUE)
gg_ordibubble(ord, env.var=dune.env$A1, var.label="A1")
Add Dendrogram to Ordination Plot
Description
Modeled after the ordicluster function in vegan, this function overlays an ordination object with a cluster dendogram. Functionality has been added to include treatment groups.
Usage
gg_ordicluster(
ord,
cluster,
treatments = NA,
choices = c(1, 2),
prune = 0,
col = 1,
pt.size = 3,
plot = TRUE
)
Arguments
ord |
An ordination object. |
cluster |
A cluster object from 'hclust' based on the same distance as 'ord.' |
treatments |
A vector assigning treatments to samples. |
choices |
Ordination axes to be plotted. |
prune |
Number of upper level hierarchies removed from the dendrogram. If prune > 0, dendrogram will be disconnected. |
col |
A vector of cluster group memberships. Used to assign colors to line segments for each cluster group. |
pt.size |
Symbol size. |
plot |
A logical; defaults to TRUE. |
Details
'treatments' should be a vector of class factor and length equal to the number of samples included in the ordination and cluster; integers are not coerced into factors.
Value
Invisibly returns a list of the data frames used to make the plot (df_ord, df_segments) and the plot itself (plot).
Author(s)
Jari Oksanen, John Quensen
Examples
data(dune)
data(dune.env)
dune.bray <- vegdist(dune, method="bray")
ord <- metaMDS(dune, k=3)
cl <- hclust(dune.bray, method="complete")
gg_ordicluster(ord, cluster=cl, treatments=dune.env$Management, prune=3, col=cutree(cl, 4))
Plot with Ellipses, Hulls, Spiders
Description
gg_ordiplot
uses ggplot2
to make an ordination plot
with group ellipses by default, and optionally hulls and/or
spiders. It is patterned after vegan
's functions ordiellipse
,
ordihull
, and ordispider
and accepts similar parameters.
Usage
gg_ordiplot(
ord,
groups,
scaling = 1,
choices = c(1, 2),
kind = c("sd", "se", "ehull"),
conf = NULL,
show.groups = "all",
ellipse = TRUE,
label = FALSE,
hull = FALSE,
spiders = FALSE,
pt.size = 3,
plot = TRUE
)
Arguments
ord |
An ordination object. |
groups |
A vector of groups. |
scaling |
Scaling for ordination plot. |
choices |
Axes to be plotted. |
kind |
Type of ellipses to show ("se", sd", "ehull"). |
conf |
Confidence value for ellipses if "se" or "sd." |
show.groups |
Subset of groups to plot. |
ellipse |
A logical for plotting ellipses; defaults to TRUE. |
label |
A logical for labeling group centroids. |
hull |
A logical for plotting group hulls. |
spiders |
A logical for plotting group spiders. |
pt.size |
Symbol size. |
plot |
A logical for plotting; defaults to TRUE. |
Value
Silently returns the plot and data frames used for the plotting.
Examples
data("dune")
data("dune.env")
dune.hel <- decostand(dune, method = "hellinger")
ord <- rda(dune.hel)
gg_ordiplot(ord, groups = dune.env$Management)
Ordisurf with ggplot2
Description
Fits a surface (contour) plot of an environmental variable to an ordination plot.
Usage
gg_ordisurf(
ord,
env.var,
groups = NA,
choices = c(1, 2),
var.label = "Level",
binwidth,
pt.size = 3,
family = "gaussian",
plot = TRUE
)
Arguments
ord |
An ordination object. |
env.var |
Environmental variable to fit to plot. |
groups |
A vector of groups (optional). |
choices |
Axes to plot. |
var.label |
Label for the contour legend; default is "Level." |
binwidth |
Controls the number of contours in the plot. |
pt.size |
Symbol size. |
family |
Error distribution and link function used by the gam function to fit the contours. |
plot |
A logical for plotting; defaults to TRUE. |
Details
By default, 'binwidth' is calculated as the difference between minimum and maximum values of the variable divided by 15.
The colors for the points are mapped to fill; if you want to rename the legend for the groups (points), use labs(fill="New name").
See the help for stats::family for possible values for family.
Value
Silently returns the plot and data frames used for the plotting.
Note
Code for extracting plot data from the ordisurf result was taken from a blog by Oliviea Rata Burge.
Author(s)
Olivia Rata Burge, John Quensen
References
https://oliviarata.wordpress.com/2014/07/17/ordinations-in-ggplot2-v2-ordisurf/'
Examples
data(varespec)
data(varechem)
vare.dist <- vegdist(varespec)
vare.mds <- monoMDS(vare.dist)
gg_ordisurf(vare.mds, env.var = varechem$Baresoil, var.label="Bare Soil")
Make Ordination Axis Labels
Description
Makes ordination axis labels that include, if appropriate, the % total variance explained by each axis.
Usage
ord_labels(ord)
Arguments
ord |
A vegan ordination object. |
Details
If there are no eigenvalues in ord, or if any eigenvalues are less than 0, each element of the vector returned has the form "DIMn" where n is the axis number. Otherwise, each element of the vector returned has the form "AxisN xx.x%" where "Axis" is taken from the vector of eigenvalues in ord if they are named or simply "DIM" if they are not, N is the number of the axis, and xx.x is the % of total variance explained by the axis.
Value
A character vector, each element of which can be used to label the corresponding axis of an ordination plot.
Examples
data("dune")
data("dune.env")
dune_hel <- decostand(dune, method = "hellinger")
ord <- rda(dune_hel)
axis_labels <- ord_labels(ord)
axis_labels[c(1,2)]
Scale Arrows to Plot
Description
Scales envfit arrows to fit within 75
Usage
scale_arrow(arrows, data, at = c(0, 0), fill = 0.75)
Arguments
arrows |
A two column data frame of coordinates from envfit result. |
data |
A two column data frame of coordinates for ordination plot. |
at |
coordinates of origin (0, 0) |
fill |
proportion of plot area to fill with maximum arrow length |
Value
Silently returns a data frame of scaled coordinates for adding arrows to ordination plot.
Author(s)
Jari Oksanen with modifications by Gavin Simpson and John Quensen
Examples
data("varespec")
data("varechem")
vare_dist <- vegdist(varespec)
vare_mds <- monoMDS(vare_dist)
plt1 <- gg_envfit(ord=vare_mds, env=varechem, plot = FALSE)
mult <- scale_arrow(plt1$df_arrows, plt1$df_ord[ , c("x", "y")])
mult