# Load data
data(dLH,package="Families")
# Age of mother at birth of a child
idego=dLH$ID[dLH$gen==1 & dLH$sex=="Female"]
idch <- IDch(idego,d=dLH)
agem <- dLH$bdated[idch] - dLH$bdated[IDmother(idch,d=dLH)]
dm <- data.frame(idego=IDmother(idch),Age=agem)
dm$Case <- "Motherhood"
# Age at grandmotherhood
idgch <- IDch(IDch(idego,d=dLH),d=dLH)
agegm <- dLH$bdated[idgch] - dLH$bdated[IDmother(IDmother(idgch,d=dLH),d=dLH)]
dgm <- data.frame(idego=IDmother(IDmother(idgch,d=dLH),d=dLH),Age=agegm)
dgm$Case <- "Grandmotherhood"
d <- rbind (dm,dgm)
d <- d[!is.na(d$Age),]
binwidth <- (max(d$Age,na.rm=TRUE)-min(d$Age,na.rm=TRUE))/60
cas <- unique(d$Case)
d$Case <- factor(d$Case,levels=cas,labels=cas,ordered=TRUE)
library(ggplot2)
p <- PlotAges(d)
Run the code above in your browser using DataLab