[R] barplot of a table

Greg Snow Greg.Snow at imail.org
Wed Jun 9 23:10:44 CEST 2010


If your data came in using read.csv then it is most likely a data frame rather than a matrix.  Try as.matrix to convert it to a matrix and then use barplot.

If that does not work then give us a sample of your data and the exact commands (copy/paste) that use used along with any errors/warnings.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Phillip Porter
> Sent: Wednesday, June 09, 2010 2:52 PM
> To: r-help at r-project.org
> Subject: [R] barplot of a table
> 
> Good morning,
> I've been dabbling in R, so my knowledge has quite a few holes in it.
> I'm
> hoping that this has a simple answer and just falls into one of those
> holes.
> 
> I have a table of percentages that I want to display as a barchart.
> Groups
> 1-4 in columns and Variables 1-5 in rows, with the percentage of each
> group
> expressing interest in each variable in the cells.  In Excel I just
> highlight the data and make a chart and it pops out with four bars
> (representing the cell values for each group) for each of the five
> variables.
> 
> What I think I need to do is barplot([mydata], beside=TRUE, [labels,
> colors,
> and text]), but I get the error "'height' must be a vector or a matrix"
> when
> I do this.  When I try this using one of the preloaded datasets
> (VADeaths) I
> can get the graph I'm looking for, but not when I read.csv my dataset.
> 
> Does anyone know what I'm doing wrong?  Can anyone point me in the
> right
> direction?
> 
> Thanks,
> Phillip
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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