I'm not sure if this is what you are looking for, but it requires a little bit of data manipulation.
If you want to manually enter your groupings in a fourth column (i.e., "Group2") for (L1,S1,S2 | L2,L3,S3,S4,S5 | L4,L5,S4,S5), you will be required to duplicate the S4 & S5 rows and place them in the appropriate group. Then you will change:
facet_wrap( ~ Group2, scales = 'free')
--
library(ggplot2)
library(reshape2)
control <- ## read in control data
control$group <- rep('control', nrow(control))
control <- melt(control, id.vars = 'group')
treatment <- ## read in control data
treatment$group <- rep('treatment', nrow(treatment))
treatment <- melt(treatment, id.vars = 'group')
allData <- rbind(control, treatment)
ggplot(allData, aes(x = variable, y = value, group = variable)) +
geom_boxplot() +
facet_wrap( ~ group, scales = 'free')
-- UPDATE --
library(gdata)
library(reshape2)
library(ggplot2)
control <- ## read in control data
control$group <- rep('control', nrow(control))
control <- melt(control, id.vars = 'group')
treatment <- ## read in treatment data
treatment$group <- rep('treatment', nrow(treatment))
treatment <- melt(treatment, id.vars = 'group')
allData <- rbind(control, treatment)
compA <- subset(allData,
variable == 'L1' |
variable == 'S1' |
variable == 'S2')
compB <- subset(allData,
variable == 'L2' |
variable == 'L3' |
variable == 'S3' |
variable == 'S4' |
variable == 'S5')
compC <- subset(allData,
variable == 'L4' |
variable == 'L5' |
variable == 'S4' |
variable == 'S5')
allData <- combine(compA, compB, compC)
ggplot(allData, aes(x = variable, y = value, group = variable, fill = group)) +
geom_boxplot() +
facet_wrap( ~ source, scales = 'free_x')