R/plot_life_cycle.R
plot_life_cycle.Rd
Plots the life cycle diagram illustrated by a matrix population model. This function processes the matrix model and passes the information to the graphViz function in DiagrammeR. See https://rich-iannone.github.io/DiagrammeR/.
plot_life_cycle(
matA,
stages,
title = NULL,
shape = "egg",
fontsize = 10,
nodefontsize = 12,
edgecol = "grey",
node_order = NULL
)
A matrix population model (i.e., a square projection matrix)
Optional vector of stage class labels. If missing, it first
attempts to infer them from dimnames(matA)
. If these are also
NULL
, then reverts to integers 1:ncol(A)
.
Optional title for the plot. Defaults to NULL
.
The shape to be used for the stages of the diagram. Any node
shape accepted by graphViz
is acceptable.
Size of the font used in the diagram.
Size of the font used in the node part of the diagram.
Colour of the arrows in the diagram.
An optional numeric vector giving the order that the nodes should be presented in the plot. Default is `NULL` whereby the order is the same as `stages`, or row/column names, of the matrix.
An object of class grViz
representing the life cycle diagram
matA <- rbind(
c(0.1, 0, 0, 0, 1.4),
c(0.5, 0.2, 0, 0, 0),
c(0, 0.3, 0.3, 0, 0),
c(0, 0, 0.4, 0.4, 0.1),
c(0, 0, 0, 0.1, 0.4)
)
plot_life_cycle(matA)
# One could save the diagram as a PNG file using a combination of `export_svg`
# (from the `DiagrammeRsvg` package) and `rsvg_png` (from the `rsvg` package)
# like this:
if (FALSE) { # \dontrun{
p1 <- plot_life_cycle(matA)
p1 %>%
DiagrammeRsvg::export_svg %>%
charToRaw() %>%
rsvg::rsvg_png("my life cycle.png")
} # }
# Change the order of the nodes and give them names
plot_life_cycle(matA,
stages = c("A", "B", "C", "D", "E"),
node_order = 5:1
)