I am trying to change the order of bar plot categories, and not sure
how to do. I am graphing temperature means (low, medium, and high)
and want them in increasing temperature order, but qplot puts them in
alphabetical order. Any way to manually instruct qplot regarding the
order.
Here is some example code. The temperatures are arranged in the order
I would like them (first column).
temp<-c(rep("Low",2),rep("Medium",2),rep("High",2))
light<-rep(c("Dark","light"),3)
avg<-dat.avg2[,3]
se<-dat.avg2[,4]
dat.avg.temp<-data.frame(cbind(avg,se))
dat.avg.temp<-data.frame(cbind(temp,light,dat.avg.temp))
dat.plot<-qplot(light,avg, fill=factor(temp),data=dat.avg.temp,
geom="bar", position="dodge")
Any help would be appreciated,
Wade
> I am trying to change the order of bar plot categories, and not sure
> how to do. I am graphing temperature means (low, medium, and high)
> and want them in increasing temperature order, but qplot puts them in
> alphabetical order. Any way to manually instruct qplot regarding the
> order.
>
> Here is some example code. The temperatures are arranged in the order
> I would like them (first column).
>
> temp<-c(rep("Low",2),rep("Medium",2),rep("High",2))
temp<-factor(c(rep("Low",2),rep("Medium",2),rep("High",2)),
levels = c("Low", "Medium", "High"))
or (to create an ordinal variable):
temp<-factor(c(rep("Low",2),rep("Medium",2),rep("High",2)),
levels = c("Low", "Medium", "High"), ordered = TRUE)
> light<-rep(c("Dark","light"),3)
> avg<-dat.avg2[,3]
> se<-dat.avg2[,4]
> dat.avg.temp<-data.frame(cbind(avg,se))
> dat.avg.temp<-data.frame(cbind(temp,light,dat.avg.temp))
> dat.plot<-qplot(light,avg, fill=factor(temp),data=dat.avg.temp,
> geom="bar", position="dodge")
HTH,
Tobias