N.Hubner at ncmls.ru.nl
2013-Nov-13 14:24 UTC
[R] making a barplot with table of experimental conditions underneath (preferably ggplot2)
Dear all, my data looks the following: df <- data.frame (experiment=c("E1","E2","E3","E4"), mean = c(3,4,5,6), stdev=c(0.1,0.1,0.05,0.2), method = c("STD","STD", "FP", "FP"), enzyme =c ("T","T/L","T","T/L"), denaturation=c("U","U","0.05%RG", "0.1%RG")) I would like to make a bar plot with standard deviation which I solved the following way: x <- df$experiment y <- df$mean sd <- df$stdev df.plot <- qplot(x,y,xlab="", ylab="# peptides identified")+ geom_bar(colour="black", fill="darkgrey")+ geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25) df.plot However, as the labels for the x-axis (the bars) I do not want the experiment number, as now, but instead a table containing the other columns of my data.frame (method, enzyme, denaturation) with the description in the front and the certain 'value' below the bars. I am looking forward to your suggestions! With best wishes, Nina ______________________________________________ Dr. Nina C. Hubner scientist quantitative proteomics Dep. of Molecular Biology, Radboud University Nijmegen, The Netherlands e-mail: n.hubner@ncmls.ru.nl tel: +31-24-3613655 Visiting address: NCMLS, Dept of Molecular Biology (route 274) Geert Grooteplein 26/28 6525 GA Nijmegen The Netherlands The Radboud University Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. [[alternative HTML version deleted]]
Jim Lemon
2013-Nov-13 21:43 UTC
[R] making a barplot with table of experimental conditions underneath (preferably ggplot2)
On 11/14/2013 01:24 AM, N.Hubner at ncmls.ru.nl wrote:> Dear all, > > > > my data looks the following: > > > > df<- data.frame (experiment=c("E1","E2","E3","E4"), mean = c(3,4,5,6), stdev=c(0.1,0.1,0.05,0.2), method = c("STD","STD", "FP", "FP"), enzyme =c ("T","T/L","T","T/L"), denaturation=c("U","U","0.05%RG", "0.1%RG")) > > > > I would like to make a bar plot with standard deviation which I solved the following way: > > > > x<- df$experiment > y<- df$mean > sd<- df$stdev > > > > df.plot<- qplot(x,y,xlab="", ylab="# peptides identified")+ > geom_bar(colour="black", fill="darkgrey")+ > geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25) > > df.plot > > > > However, as the labels for the x-axis (the bars) I do not want the experiment number, as now, but instead a table containing the other columns of my data.frame (method, enzyme, denaturation) with the description in the front and the certain 'value' below the bars. > > > > I am looking forward to your suggestions! > > >Hi Nina, This isn't in ggplot2, but it might help: library(plotrix) plotbg<-"rect(0,0,5,7,col=\"lightgray\");grid(col=\"white\",lty=1)" exp_con<-paste(df$method,df$enzyme,df$denaturation,sep="\n") barp(df$mean,names.arg=rep("",4),col="darkgray", ylab="# peptides identified",do.first=plotbg) mtext(exp_con,side=1,at=1:4,line=3) dispersion(1:4,df$mean,df$stdev) Jim
John Kane
2013-Nov-14 17:02 UTC
[R] making a barplot with table of experimental conditions underneath (preferably ggplot2)
Hi Nina, I think the following code does what you want (thanks to Jim Lemon for showing me what you wanted in terms of x-axis tick labels) However I think that barcharts are generally evil so I changed your geom_bar to geom_point. Feel free to change it back if your discipline requires it but I think it shows your data better Also you were doing some unnecessary extraction of dat from the data.frame so I just included a "data =" statement in qplot and changed the variable names in it to the original df names. This makes for cleaner and more readable code. df <- data.frame (experiment=c("E1","E2","E3","E4"), mean = c(3,4,5,6), stdev=c(0.1,0.1,0.05,0.2), method = c("STD","STD", "FP", "FP"), enzyme =c ("T","T/L","T","T/L"), denaturation=c("U","U","0.05%RG", "0.1%RG")) df$labs <- paste(df[,4],"\n ",df[,5], "\n ",df[,6]) # create labels df.plot <- qplot(experiment,mean,data = df, xlab="", ylab="# peptides identified")+ geom_point(fill="grey")+ geom_errorbar(aes(x=experiment, ymin=mean-stdev, ymax=mean+stdev), width=0.25) p + scale_x_discrete( labels = df$labs) I hop John Kane Kingston ON Canada> -----Original Message----- > From: n.hubner at ncmls.ru.nl > Sent: Wed, 13 Nov 2013 14:24:28 +0000 > To: r-help at r-project.org > Subject: [R] making a barplot with table of experimental conditions > underneath (preferably ggplot2) > > Dear all, > > my data looks the following: > > df <- data.frame (experiment=c("E1","E2","E3","E4"), mean = c(3,4,5,6), > stdev=c(0.1,0.1,0.05,0.2), method = c("STD","STD", "FP", "FP"), enzyme =c > ("T","T/L","T","T/L"), denaturation=c("U","U","0.05%RG", "0.1%RG"))> I would like to make a bar plot with standard deviation which I solved > the following way: > > x <- df$experiment > y <- df$mean > sd <- df$stdev > > df.plot <- qplot(x,y,xlab="", ylab="# peptides identified")+ > geom_bar(colour="black", fill="darkgrey")+ > geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25) > > df.plot >> However, as the labels for the x-axis (the bars) I do not want the > experiment number, as now, but instead a table containing the other > columns of my data.frame (method, enzyme, denaturation) with the > description in the front and the certain 'value' below the bars. > > I am looking forward to your suggestions! > > With best wishes, > > Nina > ______________________________________________ > > Dr. Nina C. Hubner > scientist quantitative proteomics > > Dep. of Molecular Biology, Radboud University Nijmegen, The Netherlands > e-mail: n.hubner at ncmls.ru.nl > tel: +31-24-3613655 > > Visiting address: > NCMLS, Dept of Molecular Biology (route 274) > Geert Grooteplein 26/28 > 6525 GA Nijmegen > The Netherlands > > > > > The Radboud University Medical Centre is listed in the Commercial > Register of the Chamber of Commerce under file number 41055629. > > > [[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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
John Kane
2013-Nov-15 13:58 UTC
[R] making a barplot with table of experimental conditions underneath (preferably ggplot2)
Oops, that last line of code should read df.plot + scale_x_discrete( labels = df$labs) John Kane Kingston ON Canada> -----Original Message----- > From: jrkrideau at inbox.com > Sent: Thu, 14 Nov 2013 09:02:19 -0800 > To: n.hubner at ncmls.ru.nl, r-help at r-project.org > Subject: RE: [R] making a barplot with table of experimental conditions > underneath (preferably ggplot2) > > Hi Nina, > I think the following code does what you want (thanks to Jim Lemon for > showing me what you wanted in terms of x-axis tick labels) > > However I think that barcharts are generally evil so I changed your > geom_bar to geom_point. Feel free to change it back if your discipline > requires it but I think it shows your data better > > Also you were doing some unnecessary extraction of dat from the > data.frame so I just included a "data =" statement in qplot and changed > the variable names in it to the original df names. This makes for cleaner > and more readable code. > > df <- data.frame (experiment=c("E1","E2","E3","E4"), mean = c(3,4,5,6), > stdev=c(0.1,0.1,0.05,0.2), method = c("STD","STD", "FP", "FP"), enzyme =c > ("T","T/L","T","T/L"), denaturation=c("U","U","0.05%RG", "0.1%RG")) > > df$labs <- paste(df[,4],"\n ",df[,5], "\n ",df[,6]) # create labels > > df.plot <- qplot(experiment,mean,data = df, xlab="", ylab="# peptides > identified")+ > geom_point(fill="grey")+ > geom_errorbar(aes(x=experiment, ymin=mean-stdev, ymax=mean+stdev), > width=0.25) > > p + scale_x_discrete( labels = df$labs) > > I hop > John Kane > Kingston ON Canada > > >> -----Original Message----- >> From: n.hubner at ncmls.ru.nl >> Sent: Wed, 13 Nov 2013 14:24:28 +0000 >> To: r-help at r-project.org >> Subject: [R] making a barplot with table of experimental conditions >> underneath (preferably ggplot2) >> >> Dear all, >> >> my data looks the following: >> >> df <- data.frame (experiment=c("E1","E2","E3","E4"), mean = c(3,4,5,6), >> stdev=c(0.1,0.1,0.05,0.2), method = c("STD","STD", "FP", "FP"), enzyme >> =c >> ("T","T/L","T","T/L"), denaturation=c("U","U","0.05%RG", "0.1%RG")) > >> I would like to make a bar plot with standard deviation which I solved >> the following way: >> >> x <- df$experiment >> y <- df$mean >> sd <- df$stdev >> >> df.plot <- qplot(x,y,xlab="", ylab="# peptides identified")+ >> geom_bar(colour="black", fill="darkgrey")+ >> geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25) >> >> df.plot >> > >> However, as the labels for the x-axis (the bars) I do not want the >> experiment number, as now, but instead a table containing the other >> columns of my data.frame (method, enzyme, denaturation) with the >> description in the front and the certain 'value' below the bars. >> >> I am looking forward to your suggestions! >> >> With best wishes, >> >> Nina >> ______________________________________________ >> >> Dr. Nina C. Hubner >> scientist quantitative proteomics >> >> Dep. of Molecular Biology, Radboud University Nijmegen, The Netherlands >> e-mail: n.hubner at ncmls.ru.nl >> tel: +31-24-3613655 >> >> Visiting address: >> NCMLS, Dept of Molecular Biology (route 274) >> Geert Grooteplein 26/28 >> 6525 GA Nijmegen >> The Netherlands >> >> >> >> >> The Radboud University Medical Centre is listed in the Commercial >> Register of the Chamber of Commerce under file number 41055629. >> >> >> [[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. > > ____________________________________________________________ > FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! > Check it out at http://www.inbox.com/earth____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!