[R] Side by Side Barplot Newbie Question
John Kane
jrkrideau at yahoo.ca
Wed Jul 29 21:24:06 CEST 2009
I think your data is set up incorrectly.
With your data below as "xx" try this.
# Dotcharts are often better than barplots so you might want to
# try this
================================================================
library(reshape)
mm <- melt(xx, id=c(1:2)); mm
bb <- as.matrix(cast(mm, tt ~ task, sum))
barplot(bb, beside=TRUE, col=rainbow(4))
legend("topleft", legend=row.names(bb), text.col=rainbow(4))
================================================================
# Dotcharts are often better than barplots so you might want to
# try this in place of a barplot.
dotchart(bb, col=rainbow(4))
=================================================================
--- On Wed, 7/29/09, Brindha Selvaraj <brindharhelp at gmail.com> wrote:
> From: Brindha Selvaraj <brindharhelp at gmail.com>
> Subject: [R] Side by Side Barplot Newbie Question
> To: r-help at r-project.org
> Received: Wednesday, July 29, 2009, 1:48 PM
> Hi,
>
> Many apologies for sending this twice. I accidentally
> hit the send button
> before I finished writing my mail. I am new to R and
> I hope someone can
> help me with my problem. I am trying to draw a side by side
> barplot.
>
> There is a main experiment and there are many sub
> experiments within the
> main experiment. I would like to draw a bar plot showing
> the number and type
> of sub_experiments done for each main_exp. For
> instance if the Main_Exp is
> 6, I would like to group the sub exp's for the main_exp and
> show that there
> were two sub_exp's done an ELISA and a FCM and that the
> ELISA was done once
> and the FCM was done twice. Similarly for Main_Exp 7
> I would like to show
> that for there were ELISA,FCM,qPCR,Telometry done and that
> they had a count
> of 3,3,2,5 respectively. This is what my dataset looks
> like:
>
> Main_Exp_Name Sub_Exp_Name
> Sub_Exp_Count
> 1
> ELISA
> 2
> 6
> ELISA
> 1
> 6
>
> FCM
> 2
> 7
>
> ELISA
> 3
> 7
>
> FCM
> 3
> 7
>
> Telometry
> 2
> 7
>
> qPCR
> 5
>
> The code that I have is
>
> table(comparisons_new)
> barplot(as.matrix(comparisons_new$Sub_Exp_Count),xlab="Main_Exp_Name",
> ylab="Sub_Exp_Count",ylim=c(0,10),names.arg=(comparisons_new$Main_Exp_Name),beside=TRUE,legend=rownames(comparisons_new$Sub_Exp_Name),col=rainbow(5))
>
> With this code, I am able to draw the barplot, but am
> having issues:
>
> I am not able to group them together. That is for
> each Main_Exp I am not
> able to group the Sub_Exp's under it. It all shows up as
> one continuous
> barplot without any spaces in between the Main_Exp's.
>
> Also, I would like to be able to use the same colour for a
> particular
> sub_Exp_Name no matter in which ever Main_Exp it may show
> up. But, this is
> not working for me.
>
> Please help,
>
> Brinda
>
> [[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.
>
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/
More information about the R-help
mailing list