【问题标题】:How do I position a central subtitle in my two-sided gplot-pyramid?如何在我的双面 gplot-pyramid 中定位中心字幕?
【发布时间】:2010-02-24 22:35:10
【问题描述】:

我使用 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', '')

如果有任何建议,我将不胜感激!

【问题讨论】:

    标签: r gplots


    【解决方案1】:

    怎么样

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 2019-09-10
      • 2011-04-07
      • 2022-06-16
      • 2023-01-09
      • 2012-08-07
      • 2013-06-02
      相关资源
      最近更新 更多