Skip to content

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

4 messages · N.Hubner at ncmls.ru.nl, Jim Lemon, John Kane

#
On 11/14/2013 01:24 AM, N.Hubner at ncmls.ru.nl wrote:
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
#
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
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
#
Oops, that last line  of code should read
df.plot + scale_x_discrete( labels = df$labs)

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!