This is the plot method for state sequence objects of class stslist created by the seqdef function. It produces a sequence index plot.
# S3 method for stslist
plot(x,
idxs = NULL,
weighted = TRUE,
sortv = NULL,
cpal = NULL, missing.color = NULL,
ylab = NULL,
yaxis = TRUE,
xaxis = TRUE,
ytlab = NULL,
las = par("las"),
xtlab = NULL,
xtstep = NULL,
tick.last = NULL,
cex.axis = par("cex.axis"),
sampling = NULL,
sample.meth = c("systematic","random"),
tlim, cex.plot, ylas, ...)
A state sequence object created with the seqdef function.
Indexes of the sequences to be plotted (default value is 1:10), for instance 20:50 to plot sequences 20 to 50, c(2,8,12,25) to plot sequences 2,8,12 and 25 in seqdata. If set to 0, all sequences in seqdata are plotted. When sortv is not NULL, idxs applies to the sorted sequences.
Logical: Should the bar representing each sequence be proportional to its weight? Ignored when no weights are assigned to sequences (see seqdef.)
A sorting variable or a sort method (one of "from.start" or "from.end"). See details.
Color palette for the states. A vector of colors of length equal to the number of states in the alphabet. If NULL (default), the cpal attribute of the seqdata sequence object is used (see seqdef).
Color for representing missing values inside the sequences. If NULL (default) the color is taken from the "missing.color" attribute of the x sequence object.
String. Optional label of the y-axis. If set to NA, no label is drawn.
Logical. Should the y-axis be plotted. When set as TRUE, sequence indexes are displayed.
Logical. Should the x-axis (time) be plotted? Default is TRUE.
Character string or vector of length equal to the number of sequences. Labels of the plotted sequences to be used as tick labels on the y-axis. Default is the indexes of the sequences as defined by the idxs argument. Can be set to "id" for displaying the row names (id) of the sequences instead of their indexes; row names can be assigned to the sequence object with the id argument of the seqdef function or afterwards with rownames. Otherwise ytlab can be set to a vector of length equal to the number of sequences to be plotted.
numeric in {0,1,2,3}; the orientation of tick labels.
0: always parallel to the axis (default),
1: always horizontal,
2: always perpendicular to the axis,
3: always vertical.
optional labels for the x-axis tick labels. If unspecified, the column names of the seqdata sequence object are used (see seqdef).
optional interval at which tick marks and labels of the x-axis are displayed. For example, with xtstep=3 a tick mark is drawn at position 1, 4, 7, etc... The display of the corresponding labels depends on the available space and is dealt with automatically. If unspecified, the xtstep attribute of the x object is used.
Logical. Should a tick mark be enforced at the last position on the x-axis? If unspecified, the tick.last attribute of the x object is used.
Axis annotation magnification. See par.
Integer or NULL. Size of displayed subsample of sequences. See details. If NULL (default), no sampling is applied.
Character string. Sampling method. One of "systematic" (default) and "random".
Deprecated. Use idxs instead.
Deprecated. Use cex.axis instead.
Deprecated. Use las instead.
further graphical parameters (see par) and barplot arguments.
Gilbert Ritschard
This is the default plot method for state sequence objects (produced by the seqdef function), i.e., for objects of class stslist. It produces a sequence index plot, where individual sequences are rendered with stacked bars depicting the successive states in each of the sequences.
This method is invoked by several advanced plot functions such as seqiplot and seqIplot (seqplot with type="i" or "I"), which, in addition to index plots, automatically display the state color legend and allow plotting by group.
When a sortv variable is provided, the sequences are sorted bottom-up according to its values. With sortv = "from.start", sequence are sorted by the elements of the alphabet at the successive positions starting from the beginning of the sequences. Method "from.end" proceeds similarly, but backward from the last position.
Index plots of thousands of sequences result in very heavy graphic files when stored in vectorial (PDF or POSTSCRIPT) format because each sequence, even if hidden, is drawn individually. To reduce the file size, we suggest saving the figures in bitmap format by using for instance png instead of postscript or pdf.
Alternatively, attribute sampling could be used. The maximum number of non-hidden sequences that can be shown being limited by the resolution of the output device, setting a reasonably high (about 300) subsample size of sequences to plot improves speed and output size while providing a good approximation of the full index plot. Of course, sampling applies only when the number of sequences exceeds the sampling value.
seqplot
## 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)
biofam <- biofam[500:600,] ## using a subsample only
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
"Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)
## Plot of the 10 most frequent sequences
## with bar width proportional to the frequency
plot(biofam.seq)
## Plotting the whole data set
## with no borders
plot(biofam.seq, idxs=0, space=0, border=NA)
## =======
## Weights
## =======
data(ex1)
ex1.seq <- seqdef(ex1, 1:13, weights=ex1$weights)
plot(ex1.seq)
plot(ex1.seq, weighted=FALSE)
Run the code above in your browser using DataLab