ordiggplot | R Documentation |
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)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.