如何在我的双面gplot-pyramid中放置一个中央字幕?

时间:2010-02-24 22:35:10

标签: r gplots

我使用gplots创建了一个年龄 - 性别 - 金字塔。我想在金字塔的两边之间设置一个副标题。

但是,我只能将字幕与金字塔的两面中的一面对齐:

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', '')

我会很感激任何建议!

1 个答案:

答案 0 :(得分:3)

怎么样

行文字(字幕,外= T,侧= 1,线= -1)