title: How can I change the order (categories) of my bar charts in ggplot2? and flip my legend?
body: <p>this is how my data looks </p>
  
  <pre><code>print(genderbyage)
                  Var1   Var2 Freq
  1     70 and Greater Female    4
  2  BETWEEN 12 AND 17 Female    1
  3  BETWEEN 18 AND 23 Female    8
  4  BETWEEN 24 AND 44 Female   53
  5  BETWEEN 45 AND 54 Female   33
  6  BETWEEN 55 AND 69 Female   28
  7   BETWEEN 6 AND 11 Female    6
  8        Less than 5 Female    6
  9     70 and Greater   Male    4
  10 BETWEEN 12 AND 17   Male    3
  11 BETWEEN 18 AND 23   Male   10
  12 BETWEEN 24 AND 44   Male  109
  13 BETWEEN 45 AND 54   Male   56
  14 BETWEEN 55 AND 69   Male   85
  15  BETWEEN 6 AND 11   Male    2
  16       Less than 5   Male    6
  </code></pre>
  
  <p>This is my ggplot2 code and output </p>
  
  <pre><code>ggplot(data = genderbyage, 
         mapping = aes(x = Var1, y = ifelse(Var2 == "Male", yes = -Freq, no = Freq), 
                       fill = Var2)) +
    geom_col(col = "black") +
    coord_flip() +
    scale_y_continuous(labels = abs, limits = max(genderbyage$Freq) * c(-1,1),
                       breaks = seq(-150,150,by = 25)) +
    labs(y = "Population") + 
    labs(title="Age Distribution by Male &amp; Female Genders",
         x="Age Range", 
         y="Individuals Counted",
         fill = "Gender") + 
    scale_fill_brewer(palette = "Set1")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/U4ABs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U4ABs.png" alt="enter image description here"></a></p>
  
  <p>The problem is that I need the bars to be in order that ascends. So for example I need, </p>
  
  <ol>
  <li>Less than 5</li>
  <li>BETWEEN 6 AND 11</li>
  <li>BETWEEN 12 AND 17</li>
  <li>BETWEEN 18 AND 23</li>
  <li>BETWEEN 24 AND 44</li>
  <li>BETWEEN 45 AND 54</li>
  <li>BETWEEN 55 AND 69 </li>
  <li>70 and Greater</li>
  </ol>
  
  <p>How can I rearange my bars to be in that order? </p>
  
  <p>Also how can I fix my legend so that female is on the bottom.</p>