Q:

How do I generate a boxplot using the original data order (not alphabetical)?

I am new to R. I've made a boxplot of my data but currently R is sorting the factors alphabetically. How do I maintain the original order of my data?  This is my code:
boxplot(MS~Code,data=Input)

I have 40 variables that I wish to boxplot in the same order as the original data frame lists them. I've read that I may be able to set sort.names=FALSE to maintain the original order by I don't understand where that piece of code would go.
Is there a way to redefine my Input before it goes into boxplot?
Thank you.

A:

factor the variable again as you wish in line 3
data(InsectSprays)
data <- InsectSprays
data$spray <- factor(data$spray, c("B", "C", "D", "E", "F", "G", "A"))
boxplot(count ~ spray, data = data, col = "lightgray")

The answer above is 98% of the way there.
set.seed(1)
# original order is E - A
Input <- data.frame(Code=rep(rev(LETTERS[1:5]),each=5),
                    MS=rnorm(25,sample(1:5,5)))
boxplot(MS~Code,data=Input)   # plots alphabetically

Input$Code <- with(Input,factor(Code,levels=unique(Code)))
boxplot(MS~Code,data=Input)   # plots in original order

