Basically, you just need a region <- factor(region,levels=unique(region)) to specify levels in the order in which they are displayed in the data.
Complete solution based on the data provided:
ccwelfrsts <- read.csv("GTAP_Sims.csv") ## unmangle data ccwelfrsts[5:8] <- sapply(ccwelfrsts[5:8],as.numeric) evBASE.f <- droplevels(subset(ccwelfrsts, tradlib =="BASE")) ## reorder region levels evBASE.f <- transform(evBASE.f,region=factor(region,levels=unique(region))) library(ggplot2) theme_set(theme_bw()) p <- ggplot(data = evBASE.f, aes(region, ev)) p + geom_boxplot() + theme(axis.text.x = element_text(colour = 'black', angle = 90, size = 16)) + theme(axis.text.y = element_text(colour = 'black', size = 16))+ xlab("")
You might want to switch the orientation of the graph (via coord_flip or by explicitly switching the x and y axis displays) to make labels easier to read, although most viewers are more familiar with the layout with a numerical response on the y axis.
Ben bolker
source share