ggseqtrplot | R Documentation |
Function for plotting transition rate matrix of sequence states internally
computed by TraMineR::seqtrate
\insertCitegabadinho2011ggseqplot.
Plot is generated using ggplot2
\insertCitewickham2016ggseqplot.
ggseqtrplot(
seqdata,
dss = TRUE,
group = NULL,
no.n = FALSE,
weighted = TRUE,
with.missing = FALSE,
labsize = NULL,
axislabs = "labels",
x_n.dodge = 1,
facet_ncol = NULL,
facet_nrow = NULL
)
seqdata |
State sequence object (class |
dss |
specifies if transition rates are computed for STS or DSS (default) sequences |
group |
A vector of the same length as the sequence data indicating group membership. When not NULL, a distinct plot is generated for each level of group. |
no.n |
specifies if number of (weighted) sequences is shown in grouped (faceted) graph |
weighted |
Controls if weights (specified in |
with.missing |
Specifies if missing state should be considered when computing the transition rates (default is |
labsize |
Specifies the font size of the labels within the tiles (if not specified ggplot2's default is used) |
axislabs |
specifies if sequence object's long "labels" (default) or the state names from its "alphabet" attribute should be used. |
x_n.dodge |
allows to print the labels of the x-axis in multiple rows to avoid overlapping. |
facet_ncol |
Number of columns in faceted (i.e. grouped) plot |
facet_nrow |
Number of rows in faceted (i.e. grouped) plot |
The transition rates are obtained by an internal call of
TraMineR::seqtrate
.
This requires that the input data (seqdata
)
are stored as state sequence object (class stslist
) created with
the TraMineR::seqdef
function.
As STS based transition rates tend to be dominated by high values on the diagonal, it might be
worthwhile to examine DSS sequences instead (dss = TRUE
)). In this case the resulting
plot shows the transition rates between episodes of distinct states.
In any case (DSS or STS) the transitions rates are reshaped into a a long data format
to enable plotting with ggplot2
. The resulting output then is
prepared to be plotted with ggplot2::geom_tile
.
The data and specifications used for rendering the plot can be obtained by storing the
plot as an object. The appearance of the plot can be adjusted just like with
every other ggplot (e.g., by changing the theme or the scale using +
and
the respective functions).
A tile plot of transition rates.
Marcel Raab
# Use example data from TraMineR: biofam data set
data(biofam)
# We use only a sample of 300 cases
set.seed(10)
biofam <- biofam[sample(nrow(biofam),300),]
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
"Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab, weights = biofam$wp00tbgs)
# Basic transition rate plot (with adjusted x-axis labels)
ggseqtrplot(biofam.seq, x_n.dodge = 2)
# Transition rate with group variable (with and without weights)
ggseqtrplot(biofam.seq, group=biofam$sex, x_n.dodge = 2)
ggseqtrplot(biofam.seq, group=biofam$sex, x_n.dodge = 2, weighted = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.