tags:

views:

75

answers:

1

I created an age-sex-pyramid using gplots. I would like to center a subtitle between the two sides of the pyramid.

However, I can only get the subtitle aligned with one of the two sides of the pyramid:

library(gplots)
agetable <- as.data.frame(cbind (c(2, 4, 7, 8, 10, 8, 6, 4, 2, 1), 
                                 c(1, 3, 5, 9, 11, 6, 4, 1, 0, 1)))
names(agetable) <- c("Male", "Female")
maxdir <- max(agetable)
subtitle <- "34% of data are mising age or sex"

agegraph.general.bysex <- function(agetable, maxdir, varname, miss){
agegroups <- 
if (varname=='Male') {
  datavec <- agetable[,'Male']
  lim = c(maxdir,0)
  agelabels = c('0-9','10-19','20-29','30-39','40-49','50-59',
                '60-69','70-79','80-89','90+')
} else {
  datavec <- agetable[,'Female']
  lim = c(0, maxdir)
     agelabels = ''
}
barplot2(
       datavec, horiz=TRUE, space=0, xlab = varname, xlim=lim, col='grey85',
       axisnames=TRUE, cex.axis = 1, cex.names = 1, names.arg=agelabels, 
       plot.grid=TRUE, cex.sub = 0.8, sub = miss)
}


layout(matrix(1:2, ncol=2, nrow=1))
par(las=1, adj=0.5, omi=c(0.1, 0.1, 0.1 ,0.1), cex=0.8 , cex.lab=0.8)
par(mar=c(7,5,0,0))
agegraph.general.bysex(agetable, maxdir, 'Male', subtitle)
par(mar=c(7,0,0,5))
agegraph.general.bysex(agetable, maxdir, 'Female', '')

I would be grateful for any suggestions!

+2  A: 

what about

mtext(subtitle,outer=T,side=1,line=-1)

smu
works! thank you!
Anita