demo/sec2.4.R

# Figure 2.4-1
barchart( relative.frequency ~ hemoglobin | group, data=Hemoglobin,
	horizontal=F,         # vertical bars
	layout=c(1,4),        # four panels in one column
	box.ratio=100         # make it look "histogram-y"
	)

# Calculate cumulative frequencies within groups 
hemo <- Hemoglobin[order(Hemoglobin$group),]
hemo$cumulative.frequency <- unlist(aggregate(Hemoglobin$relative.frequency, 
				by=list(Hemoglobin$group), FUN=cumsum)$x)

# Figure 2.4-2  (could use cumfreq() if we had the raw data)
xyplot(cumulative.frequency ~ hemoglobin, data=hemo,
	groups=group,
	type='l',
	ylab='cumulative relative frequency',
	xlab='hemoglobin concentration (g/dl)',
	auto.key=list(lines=TRUE,points=FALSE)
	)

Try the abd package in your browser

Any scripts or data that you put into this service are public.

abd documentation built on May 2, 2019, 4:46 p.m.