# forming conditional distribution of degree by year # then making segmented bar graph row.tot1 <- twoway[1,7];row.tot2 <- twoway[2,7];row.tot3 <- twoway[3,7]; row.tot4 <- twoway[4,7];row.tot5 <- twoway[5,7];row.tot6 <- twoway[6,7] row.tot1 cond.2001 <- c(twoway[1,1]/row.tot1, twoway[1,2]/row.tot1, twoway[1,3]/row.tot1, twoway[1,4]/row.tot1, twoway[1,5]/row.tot1, twoway[1,6]/row.tot1) cond.2001 cond.2002 <- c(twoway[2,1]/row.tot2, twoway[2,2]/row.tot2, twoway[2,3]/row.tot2, twoway[2,4]/row.tot2, twoway[2,5]/row.tot2, twoway[2,6]/row.tot2) cond.2003 <- c(twoway[3,1]/row.tot3, twoway[3,2]/row.tot3, twoway[3,3]/row.tot3, twoway[3,4]/row.tot3, twoway[3,5]/row.tot3, twoway[3,6]/row.tot3) cond.2004 <- c(twoway[4,1]/row.tot4, twoway[4,2]/row.tot4, twoway[4,3]/row.tot4, twoway[4,4]/row.tot4, twoway[4,5]/row.tot4, twoway[4,6]/row.tot4) cond.2005 <- c(twoway[5,1]/row.tot5, twoway[5,2]/row.tot5, twoway[5,3]/row.tot5, twoway[5,4]/row.tot5, twoway[5,5]/row.tot5, twoway[5,6]/row.tot5) cond.2006 <- c(twoway[6,1]/row.tot6, twoway[6,2]/row.tot6, twoway[6,3]/row.tot6, twoway[6,4]/row.tot6, twoway[6,5]/row.tot6, twoway[6,6]/row.tot6) cond.year <- matrix(c(cond.2001,cond.2002, cond.2003, cond.2004, cond.2005, cond.2006, marginal.year), nrow=6) cond.year # give column and row names to con.year matrix colnames(cond.year) <- c("2001","2002","2003","2004","2005","2006", "marginal") rownames(cond.year) <- c("Engineering","Science","Education","Health", "Humanities","Other") cond.year # finally make barplot of conditional distribution showing legend # and another barplot with smaller y range to show detail # of conditional distribution # also show marginal segmented bar to compare to the conditionals barplot(cond.year, main="PhD Degrees Given-Conditional", legend.text=TRUE, ylim=c(0,2.5)) barplot(cond.year, main="PhD Degrees Given-Conditional", ylim=c(0,1))