ggseqrplot {ggseqplot} | R Documentation |
Representative Sequence plot
Description
Function for rendering representative sequence plots with
ggplot2
(Wickham 2016) instead of base
R's plot
function that is used by
TraMineR::seqplot
(Gabadinho et al. 2011).
Usage
ggseqrplot(
seqdata,
diss,
group = NULL,
criterion = "density",
coverage = 0.25,
nrep = NULL,
pradius = 0.1,
dmax = NULL,
border = FALSE,
proportional = TRUE,
weighted = TRUE,
stats = TRUE,
colored.stats = NULL,
facet_ncol = NULL
)
Arguments
seqdata |
State sequence object (class |
diss |
pairwise dissimilarities between sequences in |
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. |
criterion |
the representativeness criterion for sorting the candidate list. One of |
coverage |
coverage threshold, i.e., minimum proportion of sequences that should have a representative in their
neighborhood (neighborhood radius is defined by |
nrep |
number of representative sequences. If |
pradius |
neighborhood
radius as a percentage of the maximum (theoretical)
distance |
dmax |
maximum theoretical distance. The |
border |
if |
proportional |
if |
weighted |
Controls if weights (specified in |
stats |
if |
colored.stats |
specifies if representatives in stats plot should be
color coded; only recommended if number of representatives is small;
if set to |
facet_ncol |
specifies the number of columns in the plot (relevant if !is.null(group)) |
Details
The representative sequence plot displays a set of distinct sequences as sequence index plot.
The set of representative sequences is extracted from the sequence data by an internal call of
TraMineR::seqrep
according to the criteria listed in the
arguments section above.
The extracted sequences are plotted by a call of ggseqiplot
which uses
ggplot2::geom_rect
to render the sequences. If stats = TRUE
the
index plots are complemented by information on the "quality" of the representative sequences.
For further details on representative sequence plots see Gabadinho et al. (2011)
and the documentation of TraMineR::plot.stslist.rep
,
TraMineR::seqplot
, and TraMineR::seqrep
.
Note that ggseqrplot
uses patchwork
to combine the different components
of the plot. If you want to adjust the appearance of the composed plot, for instance by changing the
plot theme, you should consult the documentation material of patchwork
.
Value
A representative sequence plot using ggplot
.
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.
Gabadinho A, Ritschard G, Studer M, Müller NS (2011).
“Extracting and Rendering Representative Sequences.”
In Fred A, Dietz JLG, Liu K, Filipe J (eds.), Knowledge Discovery, Knowlege Engineering and Knowledge Management, volume 128, 94–106.
Springer, Berlin, Heidelberg.
doi:10.1007/978-3-642-19032-2_7.
Wickham H (2016).
ggplot2: Elegant Graphics for Data Analysis, Use R!, 2nd ed. edition.
Springer, Cham.
doi:10.1007/978-3-319-24277-4.
Examples
# Use examples from TraMineR
library(TraMineR)
# Defining a sequence object with the data in columns 10 to 25
# (family status from age 15 to 30) in the biofam data set
data(biofam)
# Use sample of 300 cases
set.seed(123)
biofam <- biofam[sample(nrow(biofam),150),]
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
"Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)
# Computing the distance matrix
biofam.dhd <- seqdist(biofam.seq, method="DHD")
# Representative sequence plot (using defaults)
# ... with TraMineR::seqplot
seqrplot(biofam.seq, diss = biofam.dhd)
# ... with ggseqrplot
ggseqrplot(biofam.seq, diss = biofam.dhd)