ggplot2 within group bar order not following levels

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ggplot2 within group bar order not following levels

MollyHa
This post has NOT been accepted by the mailing list yet.
Hi all,

I've been trying to figure out how to change the order of the bars in my plot with no luck.  I've read quite a bit in forums detailing this, though none of the fixes I've tried seem to work.  Here's my code and the plot that I'm generating.  What I want is for each set within the larger categories to be in order from 10^-11 to 10^-9, but I can't break the 'alphabetical' ordering that is there.  

Any help would be greatly appreciated!

code:
library(ggplot2)

trtslope<-structure(list(Geno = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1a",
"1b", "1c", "1d", "1e", "1f", "2co", "2h", "4f", "5t",
"pin3", "pin3pin7"), class = "factor"), Light = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Constant", "Cycle"), class = "factor"),
    Trmt = structure(c(6L, 3L, 5L, 2L, 7L, 4L, 1L), .Label = c("None",
    "10^-11Kin", "10^-10Kin", "10^-9Kin", "10^-11IAA", "10^-10IAA",
    "10^-9IAA"), class = "factor"), mean = c(-1.54504597523189,
    -1.53362395751867, -1.57385562758997, -1.54322151503139,
    -1.66574978029235, -1.32095137998064, -1.36520900266343),
    sd = c(0.46315259286543, 0.458985115845406, 0.482009142703553,
    0.641786961061545, 0.590265055416619, 0.378034730883596,
    0.400241364404397), ste = c(0.0545830565232129, 0.0564971622467328,
    0.0607274438691926, 0.0789985139281606, 0.0647900070055787,
    0.0417469522407694, 0.0292685472783953), Conc = c("10^-10",
    "10^-10", "10^-11", "10^-11", "10^-9", "10^-9", "None"),
    Group = c("IAA", "Kinetin", "IAA", "Kinetin", "IAA", "Kinetin",
    "None")), .Names = c("Geno", "Light", "Trmt", "mean", "sd",
"ste", "Conc", "Group"), row.names = c(13L, 14L, 17L, 18L, 31L,
32L, 37L), class = "data.frame")

trtslopeplot<-ggplot(trtslope, aes(x=Group, y=mean, fill=Conc))+ geom_bar(stat="identity", position  = position_dodge())+geom_errorbar(aes(ymin=mean-ste, ymax=mean+ste),position=position_dodge(.9),width=.2)

#I've tried to reorder the factors as I've done in the past, but that doesn't seem to work to change the plot

trtslope$Trmt <- factor( as.character(trtslope$Trmt), levels=c("None","10^-11Kin","10^-10Kin","10^-9Kin","10^-11IAA","10^-10IAA","10^-9IAA"))
trtslope <- trtslope[order(trtslope$Trmt),]


plot: