gg_coefsplot: Caterpillar plots of regression coefficients from a boral...

Description Usage Arguments Examples

View source: R/coefsplot.R

Description

Constructs horizontal line plot showing 95 intervals, otherwise known as a caterpillar plot, for the column-specific regression coefficients corresponding to the covariates in X fitted in the boral model. Median coefficient values are shown as a point on each interval.

Usage

1
2
3
4
5
6
7
8
gg_coefsplot(
  model,
  X.labels = NULL,
  linesize = 1.5,
  pointsize = 3,
  palette = "Greys",
  single.colour = "black"
)

Arguments

model

A boral model fitted with one or more latent variables.

X.labels

An optional vector of text strings to use as labels for the X variables (graph facet labels). If a named vector is provided (safest), the names will be used to match labels to the X variable names in the fitted model. If NULL (default), X variable names are taken from the model.

linesize

Thickness of the line segments drawn for intervals (passed to ggplot as the size argument for geom_segment).

pointsize

Size of points representing median values (passed to ggplot as the size argument for geom_point). Set to zero if you do not want to display points.

palette

The name of the colour palette to use when colouring intervals to indicating where intervals lie in relation to zero. This should be one of the sequential palettes recognized by scale_colour_distiller. The default is "Greys". If set to NULL or "" (empty string), all intervals will be drawn in the same colour, as specified by single.colour.

single.colour

The name or hex code of a single colour to use for all intervals. This argument only applies if palette is set to NULL or "". The default single colour is black.

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
36
37
# This example is based on that for the coefsplot 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
X <- scale( spider$x )

# 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, X = X,
                      family = "negative.binomial",
                      lv.control = list(num.lv = 2),
                      mcmc.control = example.control)

gg_coefsplot(spiderfit_nb)

# Display plot again with a white background
last_plot() + theme_bw()

# Re-do plot using a different palette for the intervals
# (see help page for ggplot2::scale_colour_distiller for the
# available palette names)
#
gg_coefsplot(spiderfit_nb, palette = "Blues") +
  theme_bw()

# Draw all intervals with a single colour
# (the palette argument must be set to NULL otherwise
# it overrides the single.colour argument)
#
gg_coefsplot(spiderfit_nb, palette = NULL, single.colour = "darkred") +
  theme_bw()

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