pdf("C:\\Rmisc\\coldfish.pdf") coldfish <- read.fwf("C:\\data\\coldfish.dat", width=c(8,8), col.names=c("species","injury")) attach(coldfish) spec_inj <- species*injury spec_inj species <- factor(species,levels=1:3, labels=c("tropical","subtropical","temperate")) injury <- factor(injury,levels=1:3, labels=c("seldom","often","always")) spec_inj1 <- as.numeric(species)*as.numeric(injury) spec_inj1 sp.in.table <- table(species,injury) sp.in.table # prints out contingency table prop.table(sp.in.table,1) # Proportions of injuries by species prop.table(sp.in.table,2) # Proportions of species by injury sp.in.table/sum(sp.in.table) # Overall Proportions across table par(mfrow=c(2,2)) barplot(sp.in.table) barplot(t(sp.in.table)) barplot(sp.in.table,beside=T) barplot(t(sp.in.table),beside=T) dev.off()