plot.stslist: Plot method for state sequence objects

View source: R/plot.stslist.R

plot.stslistR Documentation

Plot method for state sequence objects


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 class 'stslist'
plot(x, idxs = NULL, weighted = TRUE, sortv = NULL,
  cpal = NULL, missing.color = NULL, ylab = NULL,
  yaxis = TRUE, xaxis = TRUE, ytlab = NULL, ylas = 0,
  xtlab = NULL, xtstep = NULL, tick.last = NULL, cex.axis = 1,
  tlim, cex.plot, ...)



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.


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. An optional label for 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 (time) axis be plotted? Default is TRUE.


the labels of the plotted sequences to display 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.


sets the orientation of the sequence labels appearing on the y axis. Accepted values are the same as for the las standard option
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 ticks labels. If unspecified, the column names of the seqdata sequence object are used (see seqdef).


optional interval at which the 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.


Deprecated. Use idxs instead.


Deprecated. Use cex.axis instead.


arguments to be passed to the plot function or other graphical parameters.


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 states over time.

This method is called by the generic seqplot function (if type="i"). The latter produces more sophisticated plots, allowing grouping and automatic display of the state color legend. The seqiplot function is a shortcut for calling seqplot with type="i".

When a sortv variable is provided to seqiplot or seqIplot, its values define the order in which the sequences are plotted. With sortv = "from.start", sequence are sorted by the elements of the alphabet at the successive positions starting from the beginning of the sequences. The "from.end" method proceeds similarly, but backward from the last position.

The interest of sequence index plots has for instance been stressed by Scherer (2001) and Brzinsky-Fay et al. (2006). Notice that such index plots for thousands of sequences result in very heavy graphic files if they are stored in PDF or POSTSCRIPT format. To reduce the size, we suggest saving the figures in bitmap format by using for instance png instead of postscript or pdf.


Gilbert Ritschard

See Also



## Defining a sequence object with the data in columns 10 to 25
## (family status from age 15 to 30) in the biofam data set
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

## Plotting the whole data set
## with no borders
plot(biofam.seq, idxs=0, space=0, border=NA)

## =======
## Weights
## =======
ex1.seq <- seqdef(ex1, 1:13, weights=ex1$weights)
plot(ex1.seq, weighted=FALSE)

TraMineR documentation built on Dec. 1, 2022, 5:08 p.m.