Sequence index plots have been introduced by
scherer2001;textualggseqplot and display each sequence as
horizontally stacked bar or line. For a more detailed discussion of this
type of sequence visualization see, for example,
brzinsky-fay2014;textualggseqplot,
fasang2014;textualggseqplot,
and raab2022;textualggseqplot.
The function uses TraMineR::seqformat
to reshape seqdata stored in wide format into a spell/episode format.
Then the data are further reshaped into the long format, i.e. for
every sequence each row in the data represents one specific sequence
position. For example, if we have 5 sequences of length 10, the long file
will have 50 rows. In the case of sequences of unequal length not every
sequence will contribute the same number of rows to the long data.
The reshaped data are used as input for rendering the index plot using
ggplot2's geom_rect. ggseqiplot uses
geom_rect instead of geom_tile
because this allows for a straight forward implementation of weights.
If weights are specified for seqdata and weighted=TRUE
the sequence height corresponds to its weight.
When using grouped plots (i.e., when group is specified) with
facet_scale = "fixed", the function internally uses scales = "free_y"
in ggplot2::facet_wrap but applies
coord_cartesian with fixed ylim
to achieve the effect of a fixed y-scale across facets. This approach allows
for consistent y-axis ranges while maintaining flexibility in the labeling.
When a sortv is specified, the sequences are arranged in the order of
its values. With sortv="from.start" sequence data are sorted
according to the states of the alphabet in ascending order starting with the
first sequence position, drawing on succeeding positions in the case of
ties. Likewise, sortv="from.end" sorts a reversed version of the
sequence data, starting with the final sequence position turning to
preceding positions in case of ties.
When ytlab is set to "id", "all", "id-all", the
y-axis labeling behavior changes. With "all", all sequences are labeled
with sequential numbers (1, 2, 3, ...) instead of using pretty breaks. With
"id", the rownames of the sequence object are used as y-axis labels with
pretty breaks. With "id-all", all sequences are labeled with their rownames.
If the sequence object has no rownames, sequential numbers (1, 2, 3, ...) are used
as identifiers. These features are especially useful when working with sorted
sequences or when displaying specific cases with meaningful identifiers. Note that
with "all" and "id-all", overlapping labels are automatically prevented
to maintain readability. When there are many sequences and insufficient space, not
all labels may be displayed. In such cases, consider increasing the plot height if you
insist on seeing all labels displayed.
Note that the default aspect ratio of ggseqiplot is different from
TraMineR::seqIplot. This is most obvious
when border=TRUE. You can change the ratio either by adding code to
ggseqiplot or by specifying the ratio when saving the code with
ggsave.