| plot.Lexis {Epi} | R Documentation |
The follow-up histories represented by a Lexis object can be plotted using one or two dimensions. The two dimensional plot is a Lexis diagram showing follow-up time simultaneously on two time scales.
## S3 method for class 'Lexis': plot(x, time.scale = NULL, breaks="lightgray", ...) ## S3 method for class 'Lexis': points(x, time.scale = NULL, ...) ## S3 method for class 'Lexis': lines(x, time.scale = NULL, ...)
x |
An object of class Lexis |
time.scale |
A vector of length 1 or 2 giving the time scales to be plotted either by name or numerical order |
breaks |
a string giving the colour of grid lines to be drawn
when plotting a split Lexis object. Grid lines can be suppressed by
supplying the value NULL to the breaks argument |
... |
Further graphical parameters to be passed to the plotting
methods.
Grids can be drawn (behind the life lines) using the following parameters in plot:
|
The plot method for Lexis objects traces ``life lines'' from
the start to the end of follow-up. The points method plots
points at the end of the life lines.
If time.scale is of length 1, the life lines are drawn
horizontally, with the time scale on the X axis and the id value on the Y
axis. If time.scale is of length 2, a Lexis diagram is
produced, with diagonal life lines plotted against both time scales
simultaneously.
If lex has been split along one of the time axes by a call to
splitLexis, then vertical or horizontal grid lines are plotted
(on top of the life lines) at the break points.
Martyn Plummer
# A small bogus cohort
xcoh <- structure( list( id = c("A", "B", "C"),
birth = c("14/07/1952", "01/04/1954", "10/06/1987"),
entry = c("04/08/1965", "08/09/1972", "23/12/1991"),
exit = c("27/06/1997", "23/05/1995", "24/07/1998"),
fail = c(1, 0, 1) ),
.Names = c("id", "birth", "entry", "exit", "fail"),
row.names = c("1", "2", "3"),
class = "data.frame" )
# Convert the character dates into numerical variables (fractional years)
xcoh$bt <- cal.yr( xcoh$birth, format="%d/%m/%Y" )
xcoh$en <- cal.yr( xcoh$entry, format="%d/%m/%Y" )
xcoh$ex <- cal.yr( xcoh$exit , format="%d/%m/%Y" )
# See how it looks
xcoh
# Define as Lexis object with timescales calendar time and age
Lcoh <- Lexis( entry = list( per=en ),
exit = list( per=ex, age=ex-bt ),
exit.status = fail,
data = xcoh )
# Default plot of follow-up
plot( Lcoh )
# With a grid and deaths as endpoints
plot( Lcoh, grid=0:10*10, col="black" )
points( Lcoh, pch=c(NA,16)[Lcoh$lex.status2+1] )
# With a lot of bells and whistles:
plot( Lcoh, grid=0:20*5, col="black", xaxs="i", yaxs="i",
xlim=c(1960,2010), ylim=c(0,50), lwd=3, las=1 )
points( Lcoh, pch=c(NA,16)[Lcoh$lex.status2+1], col="red", cex=1.5 )