ggplot2 - R ggplot - how do you specify the order of the y axis -
this question has answer here:
- change order of discrete x scale 5 answers
i trying create plot in r, simple has been bugging me days , can not work. when make plot r orders y axis alphabetical order, how specify order want. using example below:
x = c("high ind.", "high sp.", "mid ind.", "mid sp.", "low ind.", "low sp.") y = c(4.6, 2.3, 5.5, 2.2, 12.6, 3) sd = c(3.2, 1.2, 4.4, 1.5, 5.9, 1.5) qplot(x,y, xlab="water level", ylab="mean number of ind. , sp. standard deviations") + geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd, width=0.2), color="blue")
i order on y axis this: high, mid, low. r automatically puts in alphabetical order. have tried many ways fix aimed @ large more complex datasets, , not work such simple set of data. there must simple way fix this..
use factor , specify level order manually:
lv <- c("high ind.", "high sp.", "mid ind.", "mid sp.", "low ind.", "low sp.") x <- factor(lv,levels = lv) y = c(4.6, 2.3, 5.5, 2.2, 12.6, 3) sd = c(3.2, 1.2, 4.4, 1.5, 5.9, 1.5) dat<-data.frame(x, y, sd) qplot(x,y, data=dat, xlab="water level", ylab="mean number of ind. , sp. standard deviations")+geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd, width=0.2), color="blue")
Comments
Post a Comment