Learn R Programming

plotrix (version 2.6-1)

qt.plot: Quantity by interval plot

Description

Display the counts of numeric quantities against the intervals between quantities that are equal when rounded to integers.

Usage

qt.plot(qnt,qtime=NA,col=NULL,border="lightgray",
  main="Quantity x interval",xlab="Interval",ylab="Quantity",
  mar=c(5,4,4,4),...)

Arguments

qnt
Numeric vector
qtime
Numeric vector - may be a date as an integer.
col
The colors to fill the strips. NA for none.
border
border color for the polygons
main
The title of the plot.
xlab,ylab
Axis labels.
mar
margins for the plot - defaults to leave space for scale
...
additional arguments passed to plot.

Value

  • nil

Details

The intervals calculated from qtime are the x values and the counts of values of qnt are the y values of the plot displayed as the widths of sections of polygons running across the time intervals. This plot was devised to display the distribution of drinking, but may be useful for any situation in which it is desired to display the distribution of numerically coded quantities against the intervals between their occurrence. Note that if there are many values and many intervals, the resulting plot will be mostly empty. Categorizing the values and intervals so that there are only three or four categories will often produce a more informative plot. qt.plot assumes that the values in qtime represent interpretable intervals like seconds or days. The default is to assume sequential time intervals. If qtime contains dates, they must be translated to numeric format. These values will be sorted by the function. If qtime is NA, it will be assigned 1:length(qnt).

See Also

polygon

Examples

Run this code
# first a moderate drinker with frequent bigger sessions
 qnt<-sample(0:5,365,TRUE,prob=c(0.02,0.1,0.4,0.3,0.1,0.08))
 qtdates<-seq(as.Date("2007-01-01"),as.Date("2007-12-31"),by=1)
 qt.plot(qnt,as.numeric(qtdates),xlab="Number of days interval",
  ylab="Standard drinks per session")
 # now add monthly bigger sessions and notice how this
 qnt[c(30,60,90,120,150,180,210,240,270,300,330,360)]<-rep(4:5,length.out=12)
 qt.plot(qnt,as.numeric(qtdates),xlab="Number of days interval",
  ylab="Standard drinks per session")

Run the code above in your browser using DataLab