[R] preparing data for barplot()

Andrew Ziem ahz001 at gmail.com
Thu Mar 5 20:50:59 CET 2009

Hello Petr,

Thank you.  That works beautifully.  I searched for a way to transpose
a data frame, but you are right: barplot() wants a matrix.


On Wed, Mar 4, 2009 at 1:49 AM, Petr PIKAL <petr.pikal at precheza.cz> wrote:
> Read what barplot does and look to your plot.
> If you want each row to be plotted as stacked bar with names uder each bar
> taken from peaople variable then you need to
> transpose your matrix - barplot takes columns
> plot without names - you do not want them really plotted
> add names under each bar - that is what names.arg is for
> barplot(t(data.matrix(fakedata[,-1])), names.arg=fakedata$people)
> Regards
> Petr
> r-help-bounces at r-project.org napsal dne 03.03.2009 19:00:12:
>> What is the best way to produce a barplot from my data?  I would like
>> the barplot to show each person with the values stacked
>> val1+val2+val3, so there is one bar for each person  When I use
>> barplot(data.matrix(realdata)), it shows one bar for each value
>> instead.

More information about the R-help mailing list