[R] Bargraphs by a Newbie

jim holtman jholtman at gmail.com
Sun Sep 10 23:47:08 CEST 2006


Month is a factor so you have to change it to character:

> barplot(x$Births, names.arg=as.character(x$Month))


On 9/10/06, David Arnold <dwarnold45 at cox.net> wrote:
> 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.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list