[R] Bargraphs by a Newbie

David Arnold dwarnold45 at cox.net
Sun Sep 10 22:58:57 CEST 2006


All,

I have this data saved in the file bargraph.dat:

Month Births Deaths
January 305 218
February 289 191
March 313 198
April 342 189
May 311 195
June 324 182
July 345 192
August 341 178
September 353 176
October 329 193
November 304 189
December 324 192

I start an R session, change to the directory containin bargraph.dat,  
and:

 > bd=read.table("bargraph.dat",header=T)
 > bd
        Month Births Deaths
1    January    305    218
2   February    289    191
3      March    313    198
4      April    342    189
5        May    311    195
6       June    324    182
7       July    345    192
8     August    341    178
9  September    353    176
10   October    329    193
11  November    304    189
12  December    324    192

Seems successful. But when I try:

 > attach(bd)
 > barplot(Births,names.arg=Month)

I get a barplot with labels on the bottom that are the "numbers" of  
the months, and they are unordered. Can the above code be used to get  
the actual names of the months?

I did get this to work.

 > b=Births
 > names(b)=Month
 > barplot(b)

This does show the names of the months below each bar. However,  
because the names are so long, not all show up unless I manually  
enlarge the size of the window with the mouse. This raises a second  
question. How can I rotate the names of the months in this last graph  
90 degrees?

Thanks.



More information about the R-help mailing list