Basically you just need region <- factor(region,levels=unique(region))
to specify the levels in the order in which they appear in the data.
A full solution based on the data you 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 consider switching the orientation of the graph (via coord_flip
or by explicitly switching x and y axis mappings) to make the labels easier to read, although the layout with the numerical response on the y axis is more familiar to most viewers.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…