r - How do I generate a boxplot using the original data order (not alphabetical)? -
i new r. i've made boxplot of data r sorting factors alphabetically. how maintain original order of data? code:
boxplot(ms~code,data=input)
i have 40 variables wish boxplot in same order original data frame lists them. i've read may able set sort.names=false maintain original order don't understand piece of code go.
is there way redefine input before goes boxplot?
thank you.
factor variable again 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 98% of way there.
set.seed(1) # original order e - 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
Comments
Post a Comment