Aplot), rates versus period connected within age-groups
(Pplot) and rates and rates versus date of birth cohort
(Cplot). rateplot is a wrapper for these, allowing
to produce the four classical displays with a single call.
rateplot( rates, which = c("ap","ac","pa","ca"), age = as.numeric( dimnames( rates )[[1]] ), per = as.numeric( dimnames( rates )[[2]] ), grid = FALSE, a.grid = grid, p.grid = grid, c.grid = grid, ygrid = grid, col.grid = gray( 0.9 ), a.lim = range( age, na.rm=TRUE ) + c(0,diff( range( age ) )/30), p.lim = range( per, na.rm=TRUE ) + c(0,diff( range( age ) )/30), c.lim = NULL, ylim = range( rates[rates>0], na.rm=TRUE ), at = NULL, labels = paste( at ), a.lab = "Age at diagnosis", p.lab = "Date of diagnosis", c.lab = "Date of birth", ylab = "Rates", type = "l", lwd = 2, lty = 1, log.ax = "y", las = 1, ann = FALSE, a.ann = ann, p.ann = ann, c.ann = ann, xannx = 1/20, cex.ann = 0.8, a.thin = seq( 1, length( age ), 2 ), p.thin = seq( 1, length( per ), 2 ), c.thin = seq( 2, length( age ) + length( per ) - 1, 2 ), col = par( "fg" ), a.col = col, p.col = col, c.col = col, ... )
Aplot( rates, age = as.numeric( dimnames( rates )[[1]] ), per = as.numeric( dimnames( rates )[[2]] ), grid = FALSE, a.grid = grid, ygrid = grid, col.grid = gray( 0.9 ), a.lim = range( age, na.rm=TRUE ), ylim = range( rates[rates>0], na.rm=TRUE ), at = NULL, labels = paste( at ), a.lab = names( dimnames( rates ) )[1], ylab = deparse( substitute( rates ) ), type = "l", lwd = 2, lty = 1, col = par( "fg" ), log.ax = "y", las = 1, c.col = col, p.col = col, c.ann = FALSE, p.ann = FALSE, xannx = 1/20, cex.ann = 0.8, c.thin = seq( 2, length( age ) + length( per ) - 1, 2 ), p.thin = seq( 1, length( per ), 2 ), p.lines = TRUE, c.lines = !p.lines, ... )
Pplot( rates, age = as.numeric( dimnames( rates )[[1]] ), per = as.numeric( dimnames( rates )[[2]] ), grid = FALSE, p.grid = grid, ygrid = grid, col.grid = gray( 0.9 ), p.lim = range( per, na.rm=TRUE ) + c(0,diff(range(per))/30), ylim = range( rates[rates>0], na.rm=TRUE ), p.lab = names( dimnames( rates ) )[2], ylab = deparse( substitute( rates ) ), at = NULL, labels = paste( at ), type = "l", lwd = 2, lty = 1, col = par( "fg" ), log.ax = "y", las = 1, ann = FALSE, cex.ann = 0.8, xannx = 1/20, a.thin = seq( 1, length( age ), 2 ), ... )
Cplot( rates, age = as.numeric( rownames( rates ) ), per = as.numeric( colnames( rates ) ), grid = FALSE, c.grid = grid, ygrid = grid, col.grid = gray( 0.9 ), c.lim = NULL, ylim = range( rates[rates>0], na.rm=TRUE ), at = NULL, labels = paste( at ), c.lab = names( dimnames( rates ) )[2], ylab = deparse( substitute( rates ) ), type = "l", lwd = 2, lty = 1, col = par( "fg" ), log.ax = "y", las = 1, xannx = 1/20, ann = FALSE, cex.ann = 0.8, a.thin = seq( 1, length( age ), 2 ), ... )c("ap","ac","apc","pa","ca"), indication which plots should
be produced. One plot per element is produced. The first letter
indicates the x-axis of the plot, the remaining which groups
should be connected, i.e. "pa" will plot rates versus
period and connect age-classes, and "apc" will plot rates
versus age, and connect both periods and cohorts.rates as numeric.rates as numeric."l"."apcyr", indicating
which axes should be logarithmic. "y" and "r" both
refer to the rate scale. Defaults to "y".par.matlines when
plotting the curves.NULL. The function is used for its side-effect, the plot.
apc.frame
data( blcaIT )
attach(blcaIT)
# Table of rates:
bl.rate <- tapply( D, list(age,period), sum ) /
tapply( Y, list(age,period), sum )
bl.rate
# The four classical plots:
par( mfrow=c(2,2) )
rateplot( bl.rate*10^6 )
# The labels on the vertical axis could be nicer:
rateplot( bl.rate*10^6, at=10^(-1:3), labels=c(0.1,1,10,100,1000) )
# More bells an whistles
par( mfrow=c(1,3), mar=c(3,3,1,1), oma=c(0,3,0,0), mgp=c(3,1,0)/1.6 )
rateplot( bl.rate*10^6, ylab="", ann=TRUE, which=c("AC","PA","CA"),
at=10^(-1:3), labels=c(0.1,1,10,100,1000),
col=topo.colors(11), cex.ann=1.2 )
Run the code above in your browser using DataLab