[R] barplot for a categorial variable

Bill.Venables at csiro.au Bill.Venables at csiro.au
Thu Jul 31 02:18:38 CEST 2008


Try

with(yourData, barplot(table(Type)))

or, if you really want percentages something like

with(yourData, barplot(table(Type)/length(Type)*100, ylab =
"Percentage")) 

(BTW, it would be nice to know who you are.)


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of kayj
Sent: Thursday, 31 July 2008 8:14 AM
To: r-help at r-project.org
Subject: [R] barplot for a categorial variable


Hi all,

I have data with several columns and rows. one of the column is "Type"
that
can be either A, B, C or D.
I need to plot the "Type" variable as a bar plot where the x axis is the
type A, B ,C or D and the y axis shows the percentage. I was not able to
get
a bar plot. it seems that I need to convert the categorial variable into
numeric values. Is there any way how to get the bar plot without doing
the
conversion,

Thanks 
-- 
View this message in context:
http://www.nabble.com/barplot-for-a-categorial-variable-tp18743744p18743
744.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org 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.



More information about the R-help mailing list