gg_lvsplot: Plot the latent variables from a boral model

Description Usage Arguments Value Note See Also Examples

View source: R/lvsplot.R

Description

This is a ggplot version of the boral function lvsplot to draw an ordination-style graph of latent variables (sites or objects) and their corresponding coefficients (species or attributes).

Usage

1
2
3
4
5
6
gg_lvsplot(
  model,
  scaling = 1,
  lvs = c(1, 2),
  include = c("both", "objects", "attributes")
)

Arguments

model

A boral model fitted with one or more latent variables.

scaling

A numeric value between 0.8 and 1.2 that controls the relative scaling of latent variables (e.g. sites) and latent variable coefficients (e.g. species).

lvs

Integer indices of the latent variables to plot.

include

One of the following: 'both' (default) to display both objects and attributes; 'objects' to display objects only; or 'attributes' to display attributes only.

Value

A ggplot object for the latent variable graph.

Note

Presently this function only graphs two latent variables.

See Also

gg_lvsplot_data

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This example is based on that for the lvsplot function
# in the boral package and requires an example dataset from the
# mvabund package.
library(boral)
library(ggboral)

data(spider, package = "mvabund")
y <- spider$abun

# Warning - these settings are only to make the example run quickly.
# Don't use them for a real analysis!
example.control <- list(n.burnin = 10, n.iteration = 100, n.thin = 1)

spiderfit_nb <- boral(y, family = "negative.binomial",
                      lv.control = list(num.lv = 2),
                      row.eff = "fixed",
                      mcmc.control = example.control)

gg_lvsplot(spiderfit_nb)

# Since the function returns a ggplot object you can tweak it further.
# Here we add labels and a white background.
last_plot() +
  labs(x = "Latent variable 1", y = "Latent variable 2",
       title = "Example unconstrained model of spider abundance") +

  theme_bw()

# Only display sites (objects) and not species (attributes)
#
gg_lvsplot(spiderfit_nb, include = "obj") +
  labs(x = "Latent variable 1", y = "Latent variable 2",
       title = "Site relationships from unconstrained model") +

  theme_bw()

mbedward/ggboral documentation built on June 27, 2020, 10:15 a.m.