Devon got there before me but as he mentioned the id.vars needs to be set to 'gene'
Here's a boxplot with scatterplot overlay for anyone else arriving here from Google.
I do agree that ggplot can be difficult to work with. Many functions redundant in the sense that they do the same thing as other but have different names, and conflicts frequently arise. That said, if you can master ggplot, then you can produce very nice graphics for publications.
require(reshape2)
require(ggplot2)
ex <- melt(df, id.vars=c("gene"))
colnames(ex) <- c("gene","group","exprs")
ggplot(data=ex, aes(x=group, y=exprs)) +
geom_boxplot(position=position_dodge(width=0.5), outlier.shape=17, outlier.colour="red", outlier.size=0.1, aes(fill=group)) +
#Choose which colours to use; otherwise, ggplot2 choose automatically
#scale_color_manual(values=c("red3", "white", "blue")) + #for scatter plot dots
scale_fill_manual(values=c("red", "royalblue")) + #for boxplot
#Add the scatter points (treats outliers same as 'inliers')
geom_jitter(position=position_jitter(width=0.3), size=3.0, colour="black") +
#Set the size of the plotting window
theme_bw(base_size=24) +
#Modify various aspects of the plot text and legend
theme(
legend.position="none",
legend.background=element_rect(),
plot.title=element_text(angle=0, size=14, face="bold", vjust=1),
axis.text.x=element_text(angle=45, size=14, face="bold", hjust=1.10),
axis.text.y=element_text(angle=0, size=14, face="bold", vjust=0.5),
axis.title=element_text(size=14, face="bold"),
#Legend
legend.key=element_blank(), #removes the border
legend.key.size=unit(1, "cm"), #Sets overall area/size of the legend
legend.text=element_text(size=12), #Text size
title=element_text(size=12)) + #Title text size
#Change the size of the icons/symbols in the legend
guides(colour=guide_legend(override.aes=list(size=2.5))) +
#Set x- and y-axes labels
xlab("Stem cell class") +
ylab("Expression") +
#ylim(0, 0) +
ggtitle("My plot")
Thank you for such cool neat code ...