UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Barchart

The examples here are created using R 2.6.2 for Windows XP. It uses the standard graphics package that R loads automatically when it starts.

The examples below use hsb2 data set that can be downloaded as follows.

hsb2 <- read.table('http://www.ats.ucla.edu/stat/r/modules/hsb2.csv', header=T, sep=",")
attach(hsb2)
a<-table(ses)
barplot(a)

 

seslab<-as.vector(c("low","medium", "high"))
fses<-factor(ses, label=seslab)
sesstat<-table(fses)
barplot(sesstat, xlab="ses")
 
# alternatively
a<-table(ses)
seslab<-as.vector(c("low","medium", "high"))
barplot(a, names.arg=seslab, xlab="ses")
 

 

seslab<-as.vector(c("low","medium", "high"))
fses<-factor(ses, label=seslab)
sesstat<-table(fses)

barplot(sesstat, space=2, xlab="ses")

 

# change the width and spacing
# xlim is required for width=
# to take effect
barplot(sesstat, xlim=c(0,5), space=1.5, 
        width=.5, xlab="ses")
 
b<-table(ses, female)
barplot(b)

 

b<-table(ses, female)
barplot(b, beside=T, xlab="cell count 
        by ses and female")
 

 


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.