[R] Bar Chart

Jim Lemon jim at bitwrit.com.au
Thu Mar 24 08:01:23 CET 2011


On 03/24/2011 03:26 AM, blutack wrote:
> How do you do a bar chart of 2 vectors?
> I have one vector which has 10 numbers, and another which has 10 names.
> The numbers are the frequency of the corresponding name, but when I do a bar
> chart it says that there is no height. Thanks.
>
Hi blutack (any relation to Bluto?),
My guess is that you want the frequencies as the heights of the bars and 
the names as the labels of the bars:

heights<-sample(10:30,10)
bar_names<-c("Oliver","Petroushka","Queequag","Rumplestiltskin",
  "Sinbad","Tycho","Uranus","Vesalius","Wojtec","Xavier")
barplot(heights,names.arg=bar_names)

Whoops! Lost some of the labels:

library(plotrix)
barp(heights,names.arg=bar_names,staxx=TRUE)

Jim



More information about the R-help mailing list