# graph-display format (two rows, two columns)
par(mfrow = c(2,2))
# histogram of age with bin width = one year, counts
hist(cps$age, breaks=seq(29.5,59.5,1), main="Bin width = 1 yr, counts", xlab="Age")
# histogram of age with bin width = one year, density
hist(cps$age, breaks=seq(29.5,59.5,1), freq=FALSE, main="Bin width = 1 yr, density", xlab="Age")
# histogram of age with bin width = one year, counts
hist(cps$age, breaks=seq(29.5,59.5,2), main="Bin width = 2 yrs, counts", xlab="Age")
# histogram of age with bin width = one year, density
hist(cps$age, breaks=seq(29.5,59.5,2), freq=FALSE, main="Bin width = 2 yrs, density", xlab="Age")
# create subsample of the data of only "Employed" individuals
cpsemployed <- cps[cps$lfstatus=="Employed",]
# show the number of employed individuals
nrow(cpsemployed)
# graph-display format (three rows, two columns)
par(mfrow = c(3,2))
# histogram of weekly earnings with 10 bins (density on y-axis)
hist(cpsemployed$earnwk, breaks=10, freq=FALSE, main="Weekly earnings, 10 bins", xlab="Weekly earnings")
# histogram of weekly earnings with 20 bins (density on y-axis)
hist(cpsemployed$earnwk, breaks=20, freq=FALSE, main="Weekly earnings, 20 bins", xlab="Weekly earnings")
# histogram of weekly earnings with 50 bins (density on y-axis)
hist(cpsemployed$earnwk, breaks=50, freq=FALSE, main="Weekly earnings, 50 bins", xlab="Weekly earnings")
# histogram of weekly earnings with 100 bins (density on y-axis)
hist(cpsemployed$earnwk, breaks=100, freq=FALSE, main="Weekly earnings, 100 bins", xlab="Weekly earnings")
# histogram of weekly earnings with 200 bins (density on y-axis)
hist(cpsemployed$earnwk, breaks=200, freq=FALSE, main="Weekly earnings, 200 bins", xlab="Weekly earnings")
# histogram of weekly earnings with 500 bins (density on y-axis)
hist(cpsemployed$earnwk, breaks=500, freq=FALSE, main="Weekly earnings, 500 bins", xlab="Weekly earnings")
# histogram of weekly earnings with 92 bins, with estimated density overlaid
hist(cpsemployed$earnwk, breaks=92, freq=FALSE, main="", xlab="Weekly earnings")
lines(density(cpsemployed$earnwk), col="blue", lwd=2)