ParadiseA <- c(22,23.5,25,27,29.5,32,34,36.5,39.5) ParadiseB <- c(23.5,25,27,29.5,32,35.5,39) ParadiseC <- c(23.5,25.5,28.5) Developing <- c(18,21,24,27,30,33.5,37) Hutterite <- c(23,25,27,29,31,33,35,37,39) Gainj <- c(27,31,35,39) # 以上のデータは大雑把な値。正しくないかもしれない。 x <- list( ParadiseA=ParadiseA, ParadiseB=ParadiseB, ParadiseC=ParadiseC, Developing=Developing, Hutterite=Hutterite, Gainj=Gainj) mhchart <- function(LIST, ...) { require(plotrix) # gantt.chartを利用する cutlast <- function(X) { rev(rev(X)[-1]) } ex <- function(XX) { XX[-1]-0.1 } LAB <- rep(names(LIST),sapply(LIST,length)-1) STARTS <- as.vector(unlist(sapply(LIST,cutlast))) ENDS <- as.vector(unlist(sapply(LIST,ex))) DAT <- list(labels=LAB,starts=STARTS,ends=ENDS) gantt.chart(DAT,vgridlab=c(15,20,25,30,35,40,45),vgridpos=c(15,20,25,30,35,40,45), xlim=c(15,45),taskcolors="navy", main="Reconstructed maternity histories for selected populations") } mh2chart <- function(LIST, xlim=c(15,45), COL="black", FILL="white", BWD=1, ...) { # maternity history chart rev 0.1 # (C) Minato Nakazawa 5 Oct 2010. NN <- length(LIST) BASE <- rep(0,NN) names(BASE) <- names(LIST) YPOS <- barplot(BASE, horiz=TRUE, xlim=xlim, ...) for (i in 1:NN) { DAT <- LIST[[i]] NX <- length(DAT) rect(DAT[1:(NX-1)],YPOS[i]-0.5,DAT[2:NX],YPOS[i]+0.5,border=COL,col=FILL,lwd=BWD) } segments(3:9*5,0,3:9*5,YPOS[NN]+1,col="navy",lty=3) } png("mhchart.png",width=320,height=320,pointsize=10) par(family="sans") mhchart(x) dev.off() png("mh2chart.png",width=320,height=320,pointsize=10) par(family="sans", las=1, mar=c(5,7,3,2)) mh2chart(rev(x), COL="blue", FILL="pink", BWD=2, main="Maternity histories for selected populations", xlab="Maternal age (years)") dev.off()