Skip to content

Instantly share code, notes, and snippets.

@alexstorer
Created March 29, 2012 18:16
Show Gist options
  • Save alexstorer/2241411 to your computer and use it in GitHub Desktop.
Save alexstorer/2241411 to your computer and use it in GitHub Desktop.
Titled Bar Plots
hsb2 <- read.table('http://www.ats.ucla.edu/stat/R/faq/hsb2.csv', header=T, sep=",")
attach(hsb2)
sesmeans <- tapply(math, ses, mean)
femaleses = tapply(math, list(as.factor(ses), as.factor(female)), mean)
bp <- barplot(femaleses, beside = TRUE, main = "Math by SES and gender",
col = c("lightblue", "mistyrose", "lavender"),
xlab = "Gender", names = c("Male", "Female"),
ylab = "Mean Math Score", legend = c("Low", "Medium", "High"),
args.legend = list(title = "SES", x = "topright", cex = .7), ylim = c(0, 90))
text(bp, femaleses, c("dogs","cats","fish","emus","gnus","vultures"),cex=1,pos=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment