title: R ggplot, reorder function mess color code of labels when confronted to same value
body: <p>I have a problem with ggplot and colored labels</p>
  <pre><code>#example data:
  
  names&lt;-c(&quot;a&quot;,&quot;albert&quot;,&quot;aline&quot;,&quot;d&quot;,&quot;francis&quot;)
  value&lt;-c(11,10,9,9,21)
  c&lt;-c(&quot;black&quot;,&quot;red&quot;,&quot;red&quot;,&quot;black&quot;,&quot;red&quot;)
  
  df&lt;-data.frame(names,value,color)
  </code></pre>
  <p>I am trying to make a really simple barplot, with colored labels (here for the example labels that have firstname). It did this:</p>
  <pre><code>p&lt;-ggplot(data=df, aes(x=reorder(names,value), y=value)) +
    geom_bar(stat=&quot;identity&quot;)
  p+ coord_flip()+
    theme(axis.text.y = element_text(hjust = 1,colour =  reorder(c, value) ))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ZiDDY.png" rel="nofollow noreferrer">plot</a></p>
  <p>The &quot;d&quot; gets the red colot and not &quot;aline&quot;. It looke like that, when confronted to same value, the <code>reorder</code> function sort the names by inversed alphabetical order. However, when ordering the colors, it looks like the function doesn't work the same, as it doesnt color the right label.</p>
  <p>I think that way because if you change &quot;aline&quot; with &quot;eric&quot; (change the alphabetical order with &quot;d&quot;) it works the correct way.</p>
  <pre><code>names&lt;-c(&quot;a&quot;,&quot;albert&quot;,&quot;eric&quot;,&quot;d&quot;,&quot;francis&quot;)
  value&lt;-c(11,10,9,9,21)
  c&lt;-c(&quot;black&quot;,&quot;red&quot;,&quot;red&quot;,&quot;black&quot;,&quot;red&quot;)
  
  df&lt;-data.frame(names,value,color)
  p&lt;-ggplot(data=df, aes(x=reorder(names,value), y=value)) +
    geom_bar(stat=&quot;identity&quot;)
  p+ coord_flip()+
    theme(axis.text.y = element_text(hjust = 1,colour =  reorder(c, value) ))
  </code></pre>
  <p>I hope this is clear, if somebody has an idea on how to fix this, you are more than welcomed</p>