otsplot {vcrpart}R Documentation

Time-series plot for longitudinal ordinal data

Description

Plots multiple ordinal sequences in a x (usually time) versus y (response variable) scatterplot. The sequences are displayed by jittered frequency-weighted parallel lines.

Usage


## Default S3 method:
otsplot(x, y, subject, weights, groups,
        control = otsplot_control(), filter = NULL, 
        main, xlab, ylab, xlim, ylim, ...)

otsplot_control(cex = 1, lwd = 1/4, col = NULL,
                hide.col = grey(0.8), seed = NULL,
                lorder = c("background", "foreground") ,
                lcourse = c("upwards", "downwards"),
                grid.scale = 1/5, grid.lwd = 1/2,
                grid.fill =  grey(0.95), grid.col = grey(0.6),          
                layout = NULL, margins = c(5.1, 4.1, 4.1, 3.1),
                strip.fontsize = 12, strip.fill =  grey(0.9),
                pop = TRUE, newpage = TRUE, maxit = 500L)

otsplot_filter(method = c("minfreq", "cumfreq", "linear"), level = NULL) 

Arguments

x

a numeric or factor vector for the x axis, e.g. time.

y

an ordered factor vector for the y axis.

subject

a factor vector that identifies the subject, i.e., allocates elements in x and y to the subject i.e. observation unit.

weights

a numeric vector of weights of length equal the number of subjects.

groups

a numeric or factor vector of group memberships of length equal the number of subjects. When specified, one panel is generated for each distinct membership value.

control

control parameters produced by otsplot_control, such as line colors or the scale of translation zones.

filter

an otsplot_filter object which defines line coloring options. See details.

main, xlab, ylab

title and axis labels for the plot.

xlim, ylim

the x limits c(x1, x2) resp. y limits (y1,y2).

...

additional undocumented arguments.

cex

expansion factor for the squared symbols.

lwd

expansion factor for line widths. The expansion is relative to the size of the squared symbols.

col

color palette vector for line coloring.

hide.col

Color for ordinal time-series filtered-out by the filter specification in otsplot.

seed

an integer specifying which seed should be set at the beginning.

lorder

line ordering. Either "background" or "foreground".

lcourse

Method to connect simultaneous elements with the preceding and following ones. Either "upwards" (default) or "downwards".

grid.scale

expansion factor for the translation zones.

grid.lwd

expansion factor for the borders of translation zones.

grid.fill

the fill color for translation zones.

grid.col

the border color for translation zones.

strip.fontsize

fontsize of titles in stripes that appear when a groups vector is assigned.

strip.fill

color of strips that appear when a groups vector is assigned.

layout

an integer vector c(nr, nc) specifying the number of rows and columns of the panel arrangement when the groups argument is used.

margins

a numeric vector c(bottom, left, top, right) specifying the space on the margins of the plot. See also the argument mar in par.

pop

logical scalar. Whether the viewport tree should be popped before return.

newpage

logical scalar. Whether grid.newpage() should be called previous to the plot.

maxit

maximal number of iteration for the algorithm that computes the translation arrangement.

method

character string. Defines the filtering function. Available are "minfreq", "cumfreq" and "linear".

level

numeric scalar between 0 and 1. The frequency threshold for the filtering methods "minfreq" and "cumfreq".

Details

The function is a scaled down version of the seqpcplot function of the TraMineR package, implemented in the grid graphics environment.

The filter argument serves to specify filters to fade out less interesting patterns. The filtered-out patterns are displayed in the hide.col color. The filter argument expects an object produced by otsplot_filter.

otsplot_filter("minfreq", level = 0.05) colors patterns with a support of at least 5% (within a group). otsplot_filter("cumfreq", level = 0.75) highlight the 75% most frequent patterns (within group). otsplot_filter("linear") linearly greys out patterns with low support.

The implementation adopts a color palette which was originally generated by the colorspace package (Ihaka et al., 2013). The authors are grateful for these codes.

Value

otsplot returns an object of class otsplot.

otsplot_control returns an object of class otsplot_control and otsplot_filter an object of class otsplot_filter. Both these object types are specifically designed as input arguments of otsplot.

Author(s)

Reto Burgin and Gilbert Ritschard

References

Burgin, R. and G. Ritschard (2014). A Decorated Parallel Coordinate Plot for Categorical Longitudinal Data, The American Statistician 68(2), 98–103.

Ihaka, R., P. Murrell, K. Hornik, J. C. Fisher and A. Zeileis (2013). colorspace: Color Space Manipulation. R package version 1.2-4. URL https://CRAN.R-project.org/package=colorspace.

Examples

## ------------------------------------------------------------------- #
## Dummy example: 
##
## Plotting artificially generated ordinal longitudinal data
## ------------------------------------------------------------------- #

## load the data
data(vcrpart_1)
vcrpart_1 <- vcrpart_1[1:40,]

## plot the data
otsplot(x = vcrpart_1$wave, y = vcrpart_1$y, subject = vcrpart_1$id)

## using 'groups'
groups <- rep(c("A", "B"), each = nrow(vcrpart_1) / 2L)
otsplot(x = vcrpart_1$wave, y = vcrpart_1$y, subject = vcrpart_1$id,
        groups = groups)

## color series with supports over 30%
otsplot(x = vcrpart_1$wave, y = vcrpart_1$y, subject = vcrpart_1$id,
        filter = otsplot_filter("minfreq", level = 0.3))

## highlight the 50% most frequent series
otsplot(x = vcrpart_1$wave, y = vcrpart_1$y, subject = vcrpart_1$id,
        filter = otsplot_filter("cumfreq", level = 0.5))

## linearly grey out series with low support 
otsplot(x = vcrpart_1$wave, y = vcrpart_1$y, subject = vcrpart_1$id,
        filter = otsplot_filter("linear"))

## subject-wise plot 
otsplot(x = vcrpart_1$wave, y = vcrpart_1$y,
        subject = vcrpart_1$id, groups = vcrpart_1$id)

[Package vcrpart version 1.0-5 Index]