ggseqfplot {ggseqplot} | R Documentation |
Sequence Frequency Plot
Description
Function for rendering sequence index plot of the most frequent sequences of
a state sequence object using ggplot2
(Wickham 2016)
instead of base R's plot
function that is used by
TraMineR::seqplot
/
TraMineR::plot.stslist.freq
(Gabadinho et al. 2011).
Usage
ggseqfplot(
seqdata,
group = NULL,
ranks = 1:10,
weighted = TRUE,
border = FALSE,
proportional = TRUE,
ylabs = "total",
no.coverage = FALSE,
facet_ncol = NULL,
facet_nrow = NULL
)
Arguments
seqdata |
State sequence object (class |
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. |
ranks |
specifies which of the most frequent sequences should be plotted;
default is the first ten ( |
weighted |
Controls if weights (specified in |
border |
if |
proportional |
if |
ylabs |
defines appearance of y-axis labels; default ( |
no.coverage |
specifies if information on total coverage is shown as
caption or as part of the group/facet label if |
facet_ncol |
Number of columns in faceted (i.e. grouped) plot |
facet_nrow |
Number of rows in faceted (i.e. grouped) plot |
Details
The subset of displayed sequences is obtained by an internal call of
TraMineR::seqtab
. The extracted sequences are plotted
by a call of ggseqiplot
which uses
ggplot2::geom_rect
to render the sequences. 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).
Experienced ggplot2 users might notice the customized labeling of the
y-axes in the faceted plots (i.e. plots with specified group
argument). This has
been achieved by utilizing the very helpful ggh4x
library.
Value
A sequence frequency plot created by using ggplot2
.
If stored as object the resulting list object (of class gg and ggplot) also
contains the data used for rendering the plot.
Author(s)
Marcel Raab
References
Gabadinho A, Ritschard G, Müller NS, Studer M (2011).
“Analyzing and Visualizing State Sequences in R with TraMineR.”
Journal of Statistical Software, 40(4), 1–37.
doi:10.18637/jss.v040.i04.
Wickham H (2016).
ggplot2: Elegant Graphics for Data Analysis, Use R!, 2nd ed. edition.
Springer, Cham.
doi:10.1007/978-3-319-24277-4.
See Also
Examples
# Use example data from TraMineR: actcal data set
data(actcal)
# We use only a sample of 300 cases
set.seed(1)
actcal <- actcal[sample(nrow(actcal), 300), ]
actcal.lab <- c("> 37 hours", "19-36 hours", "1-18 hours", "no work")
actcal.seq <- seqdef(actcal, 13:24, labels = actcal.lab)
# sequence frequency plot
# with TraMineR::seqplot
seqfplot(actcal.seq)
# with ggseqplot
ggseqfplot(actcal.seq)
# with ggseqplot applying additional arguments and some layout changes
ggseqfplot(actcal.seq,
group = actcal$sex,
ranks = 1:5,
ylabs = "share") +
scale_x_discrete(breaks = 1:12,
labels = month.abb,
expand = expansion(add = c(0.2, 0)))