I had a similar issue and got around by changing the level of the factor. thought I'd share the code:
library(reshape2)
library(ggplot2)
group <- c(
"1",
"2-4",
"5-9",
"10-14",
"15-19",
"20-24",
"25-29",
"30-34",
"35-39",
"40-44",
"45-49"
)
xx <- factor(group, levels(factor(group))[c(1, 4, 11, 2, 3, 5:10)])
method.1 <- c(36, 14, 8, 8, 18, 1, 46, 30, 62, 34, 34)
method.2 <- c(21, 37, 45, 42, 68, 41, 16, 81, 51, 62, 14)
method.3 <- c(37, 46, 18, 9, 16, 79, 46, 45, 70, 42, 28)
elisa.neg <- c(12, 17, 18, 6, 19, 14, 13, 13, 7, 4, 1)
elisa.eq <- c(3, 6, 3, 14, 1, 4, 11, 13, 5, 3, 2)
test <- data.frame(person = xx,
"Mixture Model" = method.1,
"Censoring" = method.3,
"ELISA neg" = elisa.neg,
"ELISA eqiv" = elisa.eq)
melted <- melt(test, "person")
melted$cat <- ifelse(melted$variable == "Mixture.Model", "1",
ifelse(melted$variable == "Censoring", "2", "3"))
melted$variable = factor(melted$variable, levels = levels(melted$variable)[c(1, 2, 4,3 )]) ## This did the trick of changing the order
ggplot(melted, aes(x = cat, y = value, fill = variable)) +
geom_bar(stat = 'identity') + facet_wrap(~ person) +
theme(axis.ticks.x=element_blank(),
axis.text.x=element_blank()) +
labs(title = "My Title",
y = "Per cent", x = "Age Group", fill = "")
(Sorry, this is my data, I didn't reproduce using the data from the original post, hope it's ok!)