library(Hmisc) # Save "figure3data2.xls" as "datta.csv" x <- read.table("datta.csv", sep=",", header=TRUE)

age1 <- as.matrix(subset(x, subset=agegrp=="0-5 months", select=Cs(nashville, rochester, cincinnati))) rownames(age1) <- levels(x$year) colnames(age1) <- Cs(Nashville, Rochester, Cincinnati)

age2 <- as.matrix(subset(x, subset=agegrp=="6-23 months", select=Cs(nashville, rochester, cincinnati))) rownames(age2) <- levels(x$year) colnames(age2) <- Cs(Nashville, Rochester, Cincinnati)

age3 <- as.matrix(subset(x, subset=agegrp=="24-59 months", select=Cs(nashville, rochester, cincinnati))) rownames(age3) <- levels(x$year) colnames(age3) <- Cs(Nashville, Rochester, Cincinnati)

layout(matrix(c(0,1,1,0,2,2,3,3), ncol=4, byrow=TRUE)) barplot(t(age1), beside=TRUE, ylim=c(0, 12), axis.lty=1, ylab="Hospitalizations per 1000 children", main="0-5 months", xlab="Year", col=Cs(gray, white, black)) legend(1, 12, fill=Cs(gray, white, black), legend=Cs(Nashville, Rochester, Cincinnati))

barplot(t(age2), beside=TRUE, ylim=c(0, 12), axis.lty=1, ylab="Hospitalizations per 1000 children", main="6-23 months", xlab="Year", col=Cs(gray, white, black)) #legend(1, 12, fill=Cs(gray, white, black), # legend=Cs(Nashville, Rochester, Cincinnati))

barplot(t(age3), beside=TRUE, ylim=c(0, 12), axis.lty=1, ylab="Hospitalizations per 1000 children", main="24-59 months", xlab="Year", col=Cs(gray, white, black)) #legend(1, 12, fill=Cs(gray, white, black), # legend=Cs(Nashville, Rochester, Cincinnati))

############################################### ############################################### # Now let's create line plots... y <- read.table("figure3data.csv", header=TRUE)

with(y, plot(rate ~ as.numeric(Group), type="n", axes=FALSE, ylab="Hospitalizations per 1000 children", xlab="Age Group (months)", main="Nashville")) axis(side=2) axis(side=1, at=1:3, labels=c("0-5", "6-23", "24-59")) box() # OR #box(bty="l") # see the par() function help file

with(subset(y, location=="Nashville" & year=="2000-2001"), lines(rate ~ as.numeric(Group), pch=19, type="b", col=1)) with(subset(y, location=="Nashville" & year=="2001-2002"), lines(rate ~ as.numeric(Group), pch=19, type="b", col=2)) with(subset(y, location=="Nashville" & year=="2002-2003"), lines(rate ~ as.numeric(Group), pch=19, type="b", col=4)) with(subset(y, location=="Nashville" & year=="2003-2004"), lines(rate ~ as.numeric(Group), pch=19, type="b", col=5)) legend(3, 10, legend=levels(y$year), lty=1, col=c(1, 2, 4, 5), pch=19, xjust=1)

Edit | Attach | Print version | History: r2 < r1 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: r1 - 08 Nov 2006, TheresaScott
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback