[R] order in stacked barplot

kay kay.luebke at uni-rostock.de
Mon Nov 12 18:01:40 CET 2012


Hello
i did a stacked barplot using ggplot and R arranged the bars of the items in
different orders. i don´t know why. but i want to have the same order in
every stacked bar.
 
I used the code

data1 <- read.table("N_O_W_MAI.txt", header=TRUE, dec = ",")
attach(data1)
Teich1<-factor(Teich,levels=c(5,7,9,11,"G") ,ordered=is.ordered(Teich))
Gruppe1<-factor(Gruppe,levels=c("Annelida","Cladocera","Copepoda",
"Diptera","Ephemeroptera","Ostracoda","Sonstige"),ordered=is.ordered(Gruppe))    
data2<-data.frame(Teich1,Gruppe,Herkunft,IRI)
data2
> str(data2)
'data.frame':   65 obs. of  3 variables:
 $ Teich1: Factor w/ 5 levels "2","4","8","10",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Gruppe1: Factor w/ 7 levels "Annelida","Asellus",..: 1 2 3 4 5 6 7 1 2 3
...
 $ IRI   : num  0.606 16.274 0.326 0.396 0 ...
attach(data2)
#?data.frame
str(data2)
 library(ggplot2)

ggplot(data2, aes(Teich1,IRI, fill=Gruppe1)) +
 geom_bar(stat="summary", fun.y="sum") +
  facet_grid(~Herkunft)

So i get a plot with stacked bars for every "Teich1"(Pond), the stacks show
the summed proportion ("IRI") of the diffrent species ("Gruppe1") in every
pond.  Every species has a discret colour, but the order of species is
displayed different for the ponds. In the original data they have the same
order for every pond. This is what i want to have for the stacked barplot,
too.
Has anybody an idea?
thanks
Kay  



--
View this message in context: http://r.789695.n4.nabble.com/order-in-stacked-barplot-tp4649321.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list