PlotAges {Families}R Documentation

Plots age distribution(s) of kin

Description

Plots one or more age distributions of kin (e.g. males, females; mothers, grandmothers)

Usage

PlotAges(d, xmin = NULL, xmax = NULL, ymax = NULL, legendPos = NULL)

Arguments

d

Dataframe with at least the following columns:

  • ID

  • Age

  • Case. Case is the population category for which age distribution should be drawn (e.g. male, female).

xmin

Minimum age to be displayed on x-axis

xmax

Maximum age to be displayed on x-axis

ymax

Maximum value on y-axis (minimum is 0)

legendPos

Position of legend (position is indicated according to ggplot2 rule)

Value

p

syntax to plot age distribution(s)

Examples

# 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)


[Package Families version 2.0.2 Index]