Importing data, “Nore137″, “SampleClass”, and “Gland” below will need to be altered to reflect your column names.

library("ggplot2")
# Have column names as text, otherwise prepend X
mydata = read.table("mydata.txt", header=T, stringsAsFactors=F)
title = "Norepinephrine Levels in KO vs WT Mouse Brain"

Rplot

Handles the removal of many elements and adjusts the legend position

theme = theme_set(theme_minimal())
theme = theme_update(legend.position="top", legend.title=element_blank(), panel.grid.major.x=element_blank())

#Data
boxplot = ggplot(mydata, mapping=aes_string(y = “Nore137″, x = “SampleClass”)) + ggtitle(title)

The plot’s heavy lifting – makes a boxplot and takes away the ugly black borders. Adds a white median line in the form of a 0 width crossbar.

#Stylized Boxplot
boxplot = boxplot + geom_boxplot(outlier.colour = NULL, aes_string(colour="SampleClass", fill="SampleClass")) + # geom_boxplot(notch=T) to compare groups
stat_summary(geom = "crossbar", width=0.65, fatten=0, color="white", fun.data = function(x){ return(c(y=median(x), ymin=median(x), ymax=median(x))) })

Different axis options. If you are using facets and a legend the x-axis is redundant.

#No X Axis
theme = theme_update(axis.text.x=element_blank(), axis.ticks.x = element_blank(), axis.line.x = element_blank(), axis.title.x=element_blank())
#No Y Axis
theme = theme_update(axis.text.y=element_blank(), axis.ticks.y = element_blank(), axis.line.y = element_blank(), axis.title.y=element_blank())
#No Y Axis Label + Grey Axis Numbers
theme = theme_update(axis.line.y = element_blank(), axis.title.y=element_blank(), axis.text.y = element_text(colour="grey"), axis.ticks.y= element_line(colour="grey"))

Allows multiple scales and altered grouping. Try them out.

#Different Scale Per Facet
boxplot = boxplot + facet_wrap(~ Gland, nrow = 1, scales="free")
#Same Scale Per Facet
boxplot = boxplot + facet_grid(facets = ". ~ Gland")

Display the plot!

boxplot

Other useful code:

# n on boxes
give.n <- function(x){ return(c(ymin = median, label = length(x))) }
boxplot = boxplot + stat_summary(fun.data = give.n, geom = "text", fun.y = median)
# average on boxes
mean.n <- function(x){ return(c(y = median(x)*0.97, label = round(mean(x),2))) }
boxplot = boxplot + stat_summary(fun.data = mean.n, geom = "text", fun.y = mean, colour = "red")