[R] making a barplot with table of experimental conditions underneath (preferably ggplot2)

Jim Lemon jim at bitwrit.com.au
Wed Nov 13 22:43:52 CET 2013


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



More information about the R-help mailing list