options( pl.type="pdf" )

library( Epi )
plt( "ltab-ill", width=3, height=7, pointsize=12 )
par( mar=c(3,3,1,1) )
Lexis.diagram(age=c(50,65),date=c(1995,2000), dlab="",
              int=1, lab.int=5, las=2,
              birth.date=c(1992.3,1986.9,1990,1994.2)-50,
              entry.age=c(0,0,0,1.3),
              exit.date=c(2004,1997.5,2004,1998.7),
              fail=c(0,1,0,1),
              lwd.life=4, pch.fail=c(NA,16),
              col.life="blue" )
box()
axis(side=1, at=1996+(0:3), tick=T, las=2 )
rect( 1997,50:69,1999,51:70,lwd=4 )

plt( "Lexis-40", height=6, width=6 )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(0,40), date=c(1940,1980) )
box()

plt( "Lexis-40-3coh", height=6, width=6 )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(0,40), date=c(1940,1980) )
box()
for( cyr in seq( 1940, 1950, 5 ) )
text( seq( cyr+2.5, cyr+100, 5 ), seq( 2.5, 102.5, 5 ), paste( cyr ) )
for( l in seq(0,30,5) ) rect(l+1945,l,l+1950,l+5,lwd=2)

plt( "Lexis-40-coh", height=6, width=6 )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(0,40), date=c(1940,1980) )
box()
for( cyr in seq( 1885, 1995, 5 ) )
text( seq( cyr+2.5, cyr+100, 5 ), seq( 2.5, 102.5, 5 ), paste( cyr ) )

# An empty diagram
plt( "Lexis-x1", width=8 )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(15,60), date=c(1943,1997) )
box()

# A diagram with some life lines in it
plt( "Lexis-x2", width=8 )
e.dat <- sample(1900:1990, 50, replace=T )
x.dat <- e.dat + runif( 50, 10, 50 )
e.age <- runif( 50, 0, 25 )
fail  <- rbinom( 50, 1, 0.8 )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(15,60), date=c(1943,1997),
               entry.date = e.dat,
                exit.date = x.dat,
               entry.age  = e.age,
                     fail = fail,
                 col.fail = rep("black",2)    
               )
box()

# Diagram showing synthetic cohort
#
plt( "Lexis-coh-ill" )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(0,40), date=c(1943,1983) )
box()
text( 1970.5 + -4:4*5, 22.5 + -4:4*5, rep( "1948", 6 ) )
abline( -1943, 1 )
abline( -1953, 1 )
rect( 1948+0:6*5, 0:6*5, 1953+0:6*5, 5+0:6*5, lwd=2 )

cl <- # gray( c(3,3,3)/7 )
c("red","green2","blue")

# Diagram showing the midpoints
#
plt( "Lexis-midpoints2" )
par( mar=c(4,4,4,4), mgp=c(3,1,0)/1.5, las=1 )
Lexis.diagram( age=c(5,7), date=c(1983,1985), int=1, lab.int=1, 
            coh.grid=T, lwd.grid=2, col.grid=gray(0.6) )
abline( v=1984+1:2/3, col=cl[1], lwd=3 )
abline( h=5+1:2/3, col=cl[2], lwd=3 )
abline( 5-1/3-1984, 1, col=cl[3], lwd=3 )
abline( 5+1/3-1984, 1, col=cl[3], lwd=3 )
points( 1984+1:2/3,5+2:1/3, pch=16, cex=2)
mtext( expression(1984*textstyle(frac(1,3))),
       side=3,at=1984+1/3,line=0.75,col=cl[1])
mtext( expression(1984*textstyle(frac(2,3))),
       side=3,at=1984+2/3,line=0.75,col=cl[1])
mtext( expression(5*textstyle(frac(1,3))),
       side=2,at=5+1/3,line=0.75,col=cl[2],las=2)
mtext( expression(5*textstyle(frac(2,3))),
       side=2,at=5+2/3,line=0.75,col=cl[2],las=2)
mtext( expression(1978*textstyle(frac(2,3))),
       side=4,at=6+1/3,line=0.75,col=cl[3])
mtext( expression(1979*textstyle(frac(1,3))),
       side=4,at=5+2/3,line=0.75,col=cl[3])
eps <- 0.01
lines( c(4,4,5,4,4,5-eps,5-eps)+1980, c(5,6,6,5,5+eps,5+eps,6), lwd=5 )

# Diagram showing the midpoints
#
plt( "Lexis-midpoints3" )
par( mar=c(4,4,1,1), mgp=c(3,1,0)/1.5 )
Lexis.diagram( age=c(0,3), date=c(1982,1985), int=1, lab.int=1, 
            coh.grid=T, lwd.grid=1, col.grid="black",
            alab="Age", dlab="Period" )
abline( v=1984+1:2/3, col=cl[1], lwd=3 )
abline( h=   1+1:2/3, col=cl[2], lwd=3 )
abline( 1/3-1983, 1, col=cl[3], lwd=3 )
abline( 2/3-1983, 1, col=cl[3], lwd=3 )
points( 1982+1:2/3, 1+2:1/3, pch=16, cex=2, col=cl[2] )
points( 1984+1:2/3,   2:1/3, pch=16, cex=2, col=cl[1] )
points( 1982+c(2,4)/3,1:2/3, pch=16, cex=2, col=cl[3] )
mtext( expression( 1984 * textstyle( frac(1,3) ) ),
       side=1,at=1984+1/3,line=0.75,col=cl[1])
mtext( expression(1984*textstyle(frac(2,3))),
       side=1,at=1984+2/3,line=0.75,col=cl[1])
mtext( expression(1*textstyle(frac(1,3))),
       side=2,at=1+1/3,line=0.75,col=cl[2],las=2)
mtext( expression(1*textstyle(frac(2,3))),
       side=2,at=1+2/3,line=0.75,col=cl[2],las=2)
mtext( expression(1982*textstyle(frac(2,3))),
       side=1,at=1982+2/3,line=0.75,col=cl[3])
mtext( expression(1982*textstyle(frac(1,3))),
       side=1,at=1982+1/3,line=0.75,col=cl[3])

repp <- function( x, n ) rep( x, rep( n, length( x ) ) )

# Diagram showing the midpoints in detail
#
plt( "Lexis-midpoints3x", height=7, width=7 )
par( mar=c(4,4,3,3), mgp=c(3,1,0)/1.5 )
Lexis.diagram( age=c(0,3), date=c(1982,1985), int=1, lab.int=1,
            alab="Age", dlab="Period", 
            coh.grid=T, lwd.grid=3, col.grid="black" )
abline( v=1982+c(1:2,4:5,7:8)/3, col=cl[2], lwd=1 )
abline( h=     c(1:2,4:5,7:8)/3, col=cl[1], lwd=1 )
for( i in 1980:1984 ) 
{
abline(  1/3-i, 1, col=cl[3], lwd=1 )
abline( -1/3-i, 1, col=cl[3], lwd=1 )
}
points( repp( 1982+c(1:2,4:5,7:8)/3, 3 ),
        rep( c(2,5,8,1,4,7)/3, 3), pch=16, cex=1.5, col="black" )

mtext( expression(1979*textstyle(frac(2,3))),side=3,at=1982+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1980*textstyle(frac(1,3))),side=3,at=1983+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1980*textstyle(frac(2,3))),side=3,at=1983+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1981*textstyle(frac(1,3))),side=3,at=1984+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1981*textstyle(frac(2,3))),side=3,at=1984+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(1,3))),side=4,at=2+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(2,3))),side=4,at=2+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(1,3))),side=4,at=1+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(2,3))),side=4,at=1+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1984*textstyle(frac(1,3))),side=4,at=0+2/3,line=0.25,col=cl[3],las=1,cex=0.8)

mtext( expression(1982*textstyle(frac(1,3))),side=1,at=1982+1/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(2,3))),side=1,at=1982+2/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(1,3))),side=1,at=1983+1/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(2,3))),side=1,at=1983+2/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1984*textstyle(frac(1,3))),side=1,at=1984+1/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1984*textstyle(frac(2,3))),side=1,at=1984+2/3,line=0.45,col=cl[2],las=1,cex=0.8)

mtext( expression(  textstyle(frac(1,3))),side=2,at=  1/3,line=0.50,col=cl[1],las=1,cex=0.8)
mtext( expression(  textstyle(frac(2,3))),side=2,at=  2/3,line=0.50,col=cl[1],las=1,cex=0.8)
mtext( expression(1*textstyle(frac(1,3))),side=2,at=1+1/3,line=0.50,col=cl[1],las=1,cex=0.8)
mtext( expression(1*textstyle(frac(2,3))),side=2,at=1+2/3,line=0.50,col=cl[1],las=1,cex=0.8)
mtext( expression(2*textstyle(frac(1,3))),side=2,at=2+1/3,line=0.50,col=cl[1],las=1,cex=0.8)
mtext( expression(2*textstyle(frac(2,3))),side=2,at=2+2/3,line=0.50,col=cl[1],las=1,cex=0.8)

# Diagram showing the midpoints in detail
# with an additional panel showing risk time
plt( "Lexis-midpoints3x5-risk", width=10.5 )
par( mar=c(3,3,3,3), mgp=c(3,1,0)/1.5 )
Lexis.diagram( age=c(0,3), date=c(1980,1985), int=1, lab.int=1,
            alab="", dlab="",
            coh.grid=T, lwd.grid=1, col.grid=gray(0.7) )
mtext( "Age", side=2, at=2.5, line=par( "mgp" )[1], las=0 )
mtext( "Calendar time", side=1, at=1983.5, line=par( "mgp" )[1], las=0 )
box( col=gray(0.7) )
rect( 1980,1,1981,2,col=gray(0.9) )
segments( 1980, 1 ,1981,2,col=gray(0.7) )
eps <- 0.005
abline( v=1982+c(eps,1,2,3-eps), lwd=3 )
segments( rep(1982,4), c(eps,1,2,3-eps),
          rep(1985,4), c(eps,1,2,3-eps), lwd=3 )
segments( 1982+c(0,0,0:2), c(2:0,0,0),
          1982+c(1:3,3,3), c(3,3,3:1), lwd=3 )
segments( rep(1982,6), c(1:2,4:5,7:8)/3,
          rep(1985,6), c(1:2,4:5,7:8)/3, col=cl[1], lwd=1 )
abline( v=1982+c(1:2,4:5,7:8)/3, col=cl[2], lwd=1 )
segments( c( rep(1982,5), 1982+c(1:2,4:5,7)/3 ),
          c( 3-c(2,4:5,7:8)/3, rep(0,5) ),
          c( 1982+c(2,4:5,7:8)/3, rep(1985,5) ),
          c( rep( 3, 5), 3-c(1:2,4:5,7)/3 ),
          col=cl[3], lwd=1 )
points( repp( 1982+c(1:2,4:5,7:8)/3, 3 ),
        rep( c(2,5,8,1,4,7)/3, 3), pch=16, cex=1.5, col="black" )

mtext( expression(1979*textstyle(frac(2,3))),side=3,at=1982+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1980*textstyle(frac(1,3))),side=3,at=1983+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1980*textstyle(frac(2,3))),side=3,at=1983+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1981*textstyle(frac(1,3))),side=3,at=1984+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1981*textstyle(frac(2,3))),side=3,at=1984+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(1,3))),side=4,at=2+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(2,3))),side=4,at=2+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(1,3))),side=4,at=1+2/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(2,3))),side=4,at=1+1/3,line=0.25,col=cl[3],las=1,cex=0.8)
mtext( expression(1984*textstyle(frac(1,3))),side=4,at=0+2/3,line=0.25,col=cl[3],las=1,cex=0.8)

mtext( expression(1982*textstyle(frac(1,3))),side=1,at=1982+1/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(2,3))),side=1,at=1982+2/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(1,3))),side=1,at=1983+1/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1983*textstyle(frac(2,3))),side=1,at=1983+2/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1984*textstyle(frac(1,3))),side=1,at=1984+1/3,line=0.45,col=cl[2],las=1,cex=0.8)
mtext( expression(1984*textstyle(frac(2,3))),side=1,at=1984+2/3,line=0.45,col=cl[2],las=1,cex=0.8)

text( 1982-8*eps,  1/3, expression(  textstyle(frac(1,3))),adj=1,col=cl[1],las=1,cex=0.8)
text( 1982-8*eps,  2/3, expression(  textstyle(frac(2,3))),adj=1,col=cl[1],las=1,cex=0.8)
text( 1982-8*eps,1+1/3, expression(1*textstyle(frac(1,3))),adj=1,col=cl[1],las=1,cex=0.8)
text( 1982-8*eps,1+2/3, expression(1*textstyle(frac(2,3))),adj=1,col=cl[1],las=1,cex=0.8)
text( 1982-8*eps,2+1/3, expression(2*textstyle(frac(1,3))),adj=1,col=cl[1],las=1,cex=0.8)
text( 1982-8*eps,2+2/3, expression(2*textstyle(frac(2,3))),adj=1,col=cl[1],las=1,cex=0.8)

# The part with prevalent population
text( 1980+c(1:2/3), 1+c(2:1/3), c("A","B"), cex=2, font=2 )
segments( rep(1980+0:1,2)+rep(3*eps,4)*rep(c(1,-1),2),
          c(0,1,1,2) + 4*eps,
          rep(1980+0:1,2)+rep(3*eps,4)*rep(c(1,-1),2),
          c(0,1,1,2) + 1 - 4*eps, lwd=4 )
text( 1981+5*eps, 2.5, substitute( L[2][X][1981], list(X=",") ), adj=0 )
text( 1981+5*eps, 1.5, substitute( L[1][X][1981], list(X=",") ), adj=0 )
mtext( substitute( L[0][X][1980], list(X=",") ),side=2,at=0.5,line=0.2,las=1)
mtext( substitute( L[1][X][1980], list(X=",") ),side=2,at=1.5,line=0.2,las=1)
dev.off()

# Diagram showing the midpoints in detail
# with an additional panel showing risk time
plt( "Lexis-midpoints3x3-risk" )
par( mar=c(3,3,3,3), mgp=c(3,1,0)/1.5 )
Lexis.diagram( age=60+c(0,3), date=c(1980,1983), int=1, lab.int=1,
            alab="", dlab="",
            coh.grid=T, lwd.grid=1, col.grid=gray(0.7) )
mtext( "Age", side=2, at=62.5, line=par( "mgp" )[1], las=0 )
mtext( "Calendar time", side=1, at=1981.5, line=par( "mgp" )[1], las=0 )
box( col=gray(0.7) )
rect( 1980,61,1981,62,col=gray(0.9) )
segments( 1980, 61 ,1981, 62, col=gray(0.7) )
eps <- 0.005
lines( 1980+c(2,2,3,3,2,3) - 2*eps*c(0,0,1,1,0,0), 60+c(1,2,2,1,1,2), lwd=3 )

segments( rep(1981,2), 61+1:2/3,
          rep(1983,2), 61+1:2/3, col=cl[1], lwd=1 )
abline( v=1982+1:2/3, col=cl[2], lwd=1 )
abline( 60 - 1981 + 1/3, 1, col=cl[3] )
abline( 60 - 1981 - 1/3, 1, col=cl[3] )
points( 1982+1:2/3, 61+2:1/3, pch=16, cex=1.5, col="black" )

mtext( expression(61*textstyle(frac(1,3))),side=4,at=61+1/3,line=0.5,col=cl[1],las=1,cex=0.8)
mtext( expression(61*textstyle(frac(2,3))),side=4,at=61+2/3,line=0.5,col=cl[1],las=1,cex=0.8)

mtext( expression(1920*textstyle(frac(2,3))),side=1,at=1980+2/3,line=0.5,col=cl[3],las=1,cex=0.8)
mtext( expression(1921*textstyle(frac(1,3))),side=1,at=1981+1/3,line=0.5,col=cl[3],las=1,cex=0.8)

mtext( expression(1982*textstyle(frac(1,3))),side=1,at=1982+1/3,line=0.5,col=cl[2],las=1,cex=0.8)
mtext( expression(1982*textstyle(frac(2,3))),side=1,at=1982+2/3,line=0.5,col=cl[2],las=1,cex=0.8)

# The part with prevalent population
text( 1980+c(1:2/3), 61+c(2:1/3), c("A","B"), cex=2, font=2 )
segments( rep(1980+0:1,2)+rep(3*eps,4)*rep(c(1,-1),2),
          60+c(0,1,1,2) + 4*eps,
          rep(1980+0:1,2)+rep(3*eps,4)*rep(c(1,-1),2),
          60+c(0,1,1,2) + 1 - 4*eps, lwd=4 )
text( 1981+5*eps, 62.5, substitute( L[62][X][1981], list(X=",") ), adj=0 )
text( 1981+5*eps, 61.5, substitute( L[61][X][1981], list(X=",") ), adj=0 )
mtext( substitute( L[60][X][1980], list(X=",") ),side=2,at=60.5,line=0.2,las=1)
mtext( substitute( L[61][X][1980], list(X=",") ),side=2,at=61.5,line=0.2,las=1)
dev.off()

# Diagram illustrating the prevalent populations
#
plt( "prev-pop" )
par( mar=c(3,3,1,1), mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(0,10), date=c(1990,2000), int=1, coh.grid=T )
box()
abline( v=1990:2000, lwd=3 )
points( rep( 1990:2000, 9 ), rep( 1:9, each=11 ), pch=16, cex=0.7, col="white" )

plt( "risk-calc-0", height=6.75, width=3.75 )
par( mai=c(0.5,0.5,0.25,0.25), mgp=c(3,1,0)/1.6 )
op <- par( xaxt="n", yaxt="n" )
Lexis.diagram( age=c(0,2), date=c(0,1), int=1, lab.int=1, coh.grid=T, col.grid="black",
            alab="", dlab="" )
text( 1:2/3, c(2,4)/3, c("A","B"), font=2, cex=2 )
par( op )
axis( side=1, at=0:1, las=1, font=1, cex=2.5 )
axis( side=2, at=0:2, las=1, font=1, cex=2.5 )
dev.off()

plt( "risk-calc-1", height=6.75, width=3.75 )
par( mai=c(0.5,0.5,0.25,0.25), mgp=c(3,1,0)/1.6 )
op <- par( xaxt="n", yaxt="n" )
Lexis.diagram( age=c(0,2), date=c(0,1), int=1, lab.int=1, coh.grid=T, col.grid="black",
            alab="", dlab="" )
par( op )
#axis( side=1, at=0.5, labels=c("period    p"), tick=F, line=0 )
#axis( side=2, at=0:2, labels=c("a","a+1","a+2"), tick=F, line=0 )
lines( c(0,0.57,0.57), c(0.87,0.87,0), col="red", lwd=1 )
lines( c(0,0.57), c(0.3,0.87), col="red", lwd=2 )
points( 0.57, 0.87, pch=16, cex=1.5, col="red" )
axis( side=1, at=0.57, "p", las=1, font=2, cex=2.5 )
axis( side=2, at=0.87, "a", las=1, font=2, cex=2.5 )
dev.off()

plt( "risk-calc-2", height=6.75, width=3.75 )
par( mai=c(0.5,0.5,0.25,0.25), mgp=c(3,1,0)/1.6 )
op <- par( xaxt="n", yaxt="n" )
Lexis.diagram( age=c(0,2), date=c(0,1), int=1, lab.int=1, coh.grid=T, col.grid="black",
            alab="", dlab="" )
par( op )
#axis( side=1, at=0.5, labels=c("period    p"), tick=F, line=0 )
#axis( side=2, at=0:2, labels=c("a","a+1","a+2"), tick=F, line=0 )
lines( c(0,0.77,0.77), c(1.37,1.37,0), col="blue", lwd=1 )
lines( c(0.40,0.40), c(0,1), col="blue", lwd=1 )
lines( c(0,0.77), c(0.6,1.37), col="blue", lwd=2 )
points( 0.77, 1.37, pch=16, cex=1.5, col="blue" )
axis( side=1, at=0.77, "p", las=1, font=2, cex.lab=2.5 )
axis( side=1, at=0.40, "p-a", las=1, font=2, cex.lab=2.5 )
axis( side=2, at=1.37, "a", las=1, font=2, cex.lab=2.5 )
axis( side=2, at=1, "0", las=1, font=1, cex.lab=2.5 )
dev.off()

plt( "Lexis-fill-in", height=6, width=3)
par( mai=c(1,1,0.5,0.5)/1.5, mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(22,27), date=c(2000,2002), int=1, lab.int=1,
            coh.grid=T, col.grid="black" )
box()
dev.off()

plt( "Lexis-1943-63")
par( mai=c(1,1,0.5,0.5)/1.5, mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(40,60), date=c(1943,1963), lwd.grid=3,
            coh.grid=T, col.grid="black" )
box(lwd=3)
dev.off()

data( lungDK )
plt( "Lexis-1943-63-DY")
par( mai=c(1,1,0.5,0.5)/1.5, mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(40,60), date=c(1943,1963), lwd.grid=3,
            coh.grid=T, col.grid="black" )
# points( lungDK$Px, lungDK$Ax, pch=15, cex=2, col="pink" )
text( lungDK$Px+0.8*(0.5-lungDK$up), lungDK$Ax-0.8*(0.5-lungDK$up), 
      paste( lungDK$D,
             formatC(lungDK$Y/1000,format="f",digits=1),sep="\n"), 
      cex=1.3, font=2 )            
box(lwd=3)
dev.off()

plt( "Lexis-1943-98", width=7.5 )
par( mai=c(1,1,0.5,0.5)/1.5, mgp=c(3,1,0)/1.6 )
Lexis.diagram( age=c(40,90), date=c(1943,1998), lwd.grid=1,
            coh.grid=T, col.grid="black" )
box()
dev.off()

plt( "Lung-Lexis-dy3083-1tr" )
par( mfrow=c(1,1), mar=c(3,3,1,1), mgp=c(3,1,0)/1.5 )
lu <- read.table( file="C:/Bendix/Undervis/APC/data/lung-apc.txt", header=T )
lr <- lu[lu$A<65 & lu$P<1985 & lu$sex==1 &
         lu$A>60 & lu$P>1980,]
lr$di <- round( lr$A ) - lr$A
str( lr )
Lexis.diagram( age=c(60,65), date=c(1980,1985),
               int=1, lab.int=1, coh.grid=T )
rect( 1983, 61, 1984, 62, lwd=2, col=gray(0.95) )
segments( 1983, 61, 1984, 62, col=gray(0.7) )
#text(  lr$P-lr$di/6, lr$A+lr$di/6, paste( lr$D, round( lr$Y ), sep="\n" ) )
text(  lr$P+0.2, lr$A+lr$di/6, paste( lr$D, round( lr$Y ), sep="\n" ), adj=1 )
box()
dev.off()

