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]]
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_Na me),beside=TRUE,legend=rownames(comparisons_new$Sub_Exp_Name),col=rainbo w(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]]
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/
Hi Brindha Does this answer your question: http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html ? Cheers, Tal On Wed, Jul 29, 2009 at 8:48 PM, Brindha Selvaraj <brindharhelp@gmail.com>wrote:> 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@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. >-- ---------------------------------------------- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: http://www.r-statistics.com/ http://www.talgalili.com http://www.biostatistics.co.il [[alternative HTML version deleted]]
Seemingly Similar Threads
- side-by-side Barplot newbie question
- "FANNY" function in R package "cluster"
- Bagged clustering and fuzzy c-means
- [Bug 1743] New: Flowtable: Flows exiting OFFLOAD State being assigned value of nf_conntrack_tcp_timeout_unacknowledged
- Session rekeying support in OpenSSH