pdf("ex0107.pdf") # Read in data from ASCII formatted (Fixed With File) ex0107dat <- read.fwf("http://www.stat.ufl.edu/~winner/data/biostat/ex0107.dat", width=c(8,8), col.names=c("trt","otcm")) # Create Names for Trt and Outcomeswith Factor Commands treatment <- factor(ex0107dat$trt,levels=1:2) levels(treatment) = c("Streptomycin", "Control") outcome <- factor(ex0107dat$otcm,levels=1:6) levels(outcome) = c("CI", "MI", "NID", "MD", "CD", "Death") # Create a dataset (frame) from input data ex0107 <- data.frame(outcome, treatment) # Attach the dataset for analysis attach(ex0107) # Create a crosstabulation of treatment and outcome trtout <- table(outcome, treatment) trtout # Create a side-by-side barplot barplot(trtout, beside=T, legend.text=rownames(trtout)) dev.off()