title: Reorder labels in ggplot based on values in 2 colums
body: <p>I would like to build a bar plot in R in which the labels in x axis are ordered by the value in <code>Count</code> if <code>Name == A</code>. When I build it, it simply order the x axis "Tool 1, Tool 2, Tool 3". What I would like is to get a x axis order like "Tool 3, Tool 1, Tool 2" (ordering by values in <code>Name == A</code>). </p>
  
  <p>Here is a tiny dataframe as example:</p>
  
  <pre><code>df &lt;- rbind(tibble(Name = c('A', 'B', 'C'), Count = c(6, 3, 1), Method = rep('Tool 1', 3)),
          tibble(Name = c('A', 'B', 'C'), Count = c(4, 2, 4), Method = rep('Tool 2', 3)),
          tibble(Name = c('A', 'B', 'C'), Count = c(7, 3, 0), Method = rep('Tool 3', 3))
          )
  df
  
  # A tibble: 9 x 3
    Name  Count Method
    &lt;fct&gt; &lt;dbl&gt; &lt;chr&gt; 
  1 A         6 Tool 1
  2 B         3 Tool 1
  3 C         1 Tool 1
  4 A         4 Tool 2
  5 B         2 Tool 2
  6 C         4 Tool 2
  7 A         7 Tool 3
  8 B         3 Tool 3
  9 C         0 Tool 3
  </code></pre>
  
  <p>To build the plot: </p>
  
  <pre><code>p &lt;- ggplot(df, aes(x = Method,
                         y = Count,
                         fill = Name)) +
    geom_bar(stat="identity")
  
  p
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ZQ4Ho.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZQ4Ho.png" alt="enter image description here"></a></p>
  
  <p>I tried to rearrange it with <code>df %&gt;% mutate(Method = fct_reorder(Method, desc(Count)))</code> but I don't know how to select only by A values. I also could reorder it manually but I am interested in knowing how to do it automatically. Thanks for the help !</p>