title: How to order error bars in ggplot2 on two conditions
body: <p>I am trying to order error bars in ggplot based on two columns.  I have looked at some previously provided answers which were helpful for one column,but when I want to order on two I fail to obtain the intended result.</p>
  
  <p>This code will fulfil my firstwish of ordering teh bars based on the first column (Outcome) </p>
  
  <pre><code>ddf$Outcome &lt;- factor(ddf$Outcome, levels=c("Total", "cardva" ,  "ami" ,  "heartf" ,"dysrhy"), ordered=TRUE)
  </code></pre>
  
  <p>However, when I want to also order on column cat(with the order of whole year, cold season and warm season)  the code does not work.</p>
  
  <pre><code>ddf$cat &lt;- factor(ddf$cat, levels= c("Whole year",  "Cold","Warm"), ordered=TRUE)
  </code></pre>
  
  <p>How can I order the bars based on outcome and cat?
  The following code produces a plot with alphabetical order of column cat.  </p>
  
  <pre><code>dodge &lt;- position_dodge(width=0.9) 
  ggplot(ddf, aes(x = Outcome, y = pinc,ymin = lcinc, ymax = ucinc,  group=cat,color=cat,shape=cat))  +
    geom_point(position=dodge,size = 4) + geom_linerange(position=dodge,size =0.7) +
    geom_hline(aes(yintercept = 0))  + 
    scale_x_discrete("", labels = c("ami" = "AMI","cardva" = "Any CVD", "dysrhy" = "Dysrhythmia",
                                           "heartf" = "HF", "Total"= "All Subjects")) + theme_bw() +
    labs(colour="Period", shape="Period", y="Relative Difference (%)") +
    theme(axis.title=element_text(face="bold",size="14"),axis.text=element_text(size=14,face="bold"))
  </code></pre>
  
  <p>sample data follows</p>
  
  <pre><code>dput(ddf)
  structure(list(Outcome = structure(c(1L, 1L, 1L, 2L, 3L, 4L, 
  5L, 2L, 3L, 4L, 5L, 2L, 3L, 4L, 5L), .Label = c("Total", "cardva", 
  "ami", "heartf", "dysrhy"), class = c("ordered", "factor")), 
      pinc = c(0.50389187458233, 0.579539836910437, 0.601685513579753, 
      0.28267013091543, 1.71852544919748, -0.284681087465499, -0.315288733679508, 
      -0.214290507233894, -0.0319464172748196, -1.0103617140803, 
      0.0669795902723536, 0.338718648843339, 2.46728604502957, 
      -0.626929184485836, -1.33251808343037), lcinc = c(0.124678813009127, 
      -0.000690299706695985, 0.101542783301833, -0.317021516853733, 
      0.436205248000321, -1.32202043292773, -1.93050761165515, 
      -1.18689153946393, -2.12567063251963, -2.7029110723661, -2.57800553889581, 
      -0.573641468633246, 0.539635356054902, -2.18756799993103, 
      -3.77359786707672), ucinc = c(0.884541170935749, 1.16313666688221, 
      1.10432713392166, 0.885969516714469, 3.01721768570142, 0.763563152101443, 
      1.32653303537096, 0.767883675589554, 2.10656667282445, 0.711630697043031, 
      2.78377546784718, 1.25945080162582, 4.43189566234674, 0.958610284817674, 
      1.17048722562318), cat = c("Whole year", "Cold season", "Warm season", 
      "Whole year", "Whole year", "Whole year", "Whole year", "Cold season", 
      "Cold season", "Cold season", "Cold season", "Warm season", 
      "Warm season", "Warm season", "Warm season")), .Names = c("Outcome", 
  "pinc", "lcinc", "ucinc", "cat"), row.names = c("2", "8", "5", 
  "41", "42", "44", "45", "31", "32", "34", "35", "26", "27", "29", 
  "30"), class = "data.frame")
  </code></pre>