################################################### ### Q1: ################################################### plot(x, y, ylim=c(0.5, 2.5), axes=FALSE) box() axis(1) axis(2, at=sort(as.numeric(unique(y))), labels=levels(y)) ################################################### ### Q2: ################################################### mp <- barplot(v, density=10, xlab="Week Number", ylab="Number of Viewers", col=1) lines(mp[8:length(v)], mean.8, lty=1, lwd=2, col=2) points(mp[8:length(v)], mean.8, pch=16, col=2) mtext(as.character(1:20), side=1, at=mp, line=0) ################################################### ### Q3: ################################################### z <- t(apply(y, 1, "cumsum")) xvals <- 1:nrow(z) par(fig=c(0, 0.8, 0, 1), mar=c(4, 4, 4, 2)) plot(0, xlim = c(0, nrow(z)), ylim=c(0, 100), ylab="Cumulative Percentage", xlab="Time", axes=F, type="n", xaxs="i", yaxs = "i") for(i in 3:1) polygon(c(0, xvals, xvals[length(xvals)], rep(rev(xvals-1), each=2)), c(0, rep(0, length(xvals)), rep(z[,i], each=2), z[1, i]), col = i + 1, border = FALSE) abline(h = seq(5, 95, by = 5)) abline(v = 1:20) axis(1) axis(2, las=1) box() par(new=T) par(fig=c(0.8, 1, 0, 1), mar=c(4, 0, 4, 2)) plot(0, xlim=c(0, 1), ylim=c(0, 3), axes=F, xlab="", ylab="", type="n", xaxs="i", yaxs="i") labels <- c("System", "User", "Idle") for (i in 1:3) { polygon(c(0, 0, 0.5, 0.5), c(i-1, i, i, i-1), col=i+1) text(0.6, i-0.5, labels[i], srt=90) } ################################################### ### Q4: ################################################### par(mar=c(5, 8, 3, 8), las=1) plot(0, xlim=c(0, 1), ylim=c(1, 13), ylab="", xlab="Proportion", axes=F) mtext("Sex", side=2, at=12, cex=2, adj=1, line=1) mtext("male", side=2, at=11, adj=1, line=1) mtext("Race", side=2, at=9, cex=2, adj=1, line=1) mtext("black", side=2, at=8, adj=1, line=1) mtext("caucasian", side=2, at=7, adj=1, line=1) mtext("oriental", side=2, at=6, adj=1, line=1) mtext("other", side=2, at=5, adj=1, line=1) mtext("smoking", side=2, at=3, cex=2, adj=1, line=1) abline(h=c(2, 5,6,7,8,11), lty=2) ptsfun <- function(row, elt) { points(elt[1], row, pch=16, col=1) points(elt[1], row) points(elt[2], row, pch=16, col=2) points(elt[2], row) } ptsfun(11, propns$sex$male) ptsfun(8, propns$race$black) ptsfun(7, propns$race$caucasian) ptsfun(6, propns$race$oriental) ptsfun(5, propns$race$other) ptsfun(2, propns$smoking) mtext("P = 0.453", side=4, line=1, adj=0, at=11) mtext("P = 0.189", side=4, line=1, adj=0, at=8) mtext("P = 0.743", side=4, line=1, adj=0, at=2) axis(1) box() par(new=T) par(mar=rep(0, 4)) par(fig=c(0.85, 0.95, 0.1, 0.2)) plot(0, xlim=c(0, 1), ylim=c(1, 4), ylab="", xlab="", axes=F) points(0.33, 2, pch=16, col=2) points(0.33, 2) points(0.33, 3, pch=16) text(0.66, 2, "B") text(0.66, 3, "A") box()