title: Changes ggplot Legend gradient
body: <p>I have this data set about average growth rate of different genotypes:</p>
  <pre><code>Genotype  desv  mean  Rank
     &lt;fct&gt;    &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
    ENG2    0.345  4.29     7
    ENG20   0.255  3.90     9
    ENG22   0.185  4.19     8
    ENG24   0.341  3.84    10
    ENG25   0.195  3.51    12
    ENG3    0.267  4.38     6
    ENG32   0.262  3.61    11
    ENG4    0.223  4.49     4
    ENG5    0.359  5.13     2
    ENG7    0.122  4.49     5
    ENG8    0.182  4.90     3
    ENG9    0.459  5.28     1
  </code></pre>
  <p>And the code bellow to make a ggplot graph:</p>
  <pre><code>ggplot(growth2)+
    geom_col(aes(x=Rank, y=mean, fill=mean), width=0.7, color=&quot;Black&quot;)+
    geom_errorbar(aes(x=Rank, ymin=mean-desv, ymax=mean+desv), position = position_dodge(width=0.9),width=0.4, alpha=1)+
    theme_classic()+
    theme(axis.text.x=element_text(angle = 90, hjust =2, vjust = 0.5, family=&quot;sans&quot;, size=12, color=&quot;Black&quot;))+
    theme(axis.ticks.x = element_blank())+
    xlab(&quot;&quot;)+
    ylab(expression(paste(&quot;AGR (cm &quot;,&quot; &quot;, year^-1,&quot;)&quot;, sep=&quot;&quot;)))+
    theme(axis.line.x = element_blank())+
    theme(axis.text.y=element_text(family=&quot;sans&quot;, size=12, color=&quot;Black&quot;))+
    theme(axis.title.y= element_text(margin=margin(t=0, r=10, b=0, l=0)))+
    scale_y_continuous(breaks=c(0, 1, 2, 3, 4, 5, 6), limits = c(0,6))+
    scale_fill_gradient(low=&quot;red&quot;, high=&quot;green&quot;, name=&quot;&quot;)+
    geom_hline(yintercept = 0, color=&quot;Black&quot;)+
    theme(legend.position = c(0.5,1), legend.direction = &quot;horizontal&quot;)+
    theme(legend.text = element_blank())+
    theme(plot.margin = margin(1,0,0,0, unit = &quot;cm&quot;))+
    scale_x_continuous(breaks=c(1,2,3,4,5,6,7,8,9,10,11,12),labels = c(&quot;ENG 9 &quot;, &quot;ENG 5 &quot;, &quot;ENG 8 &quot;, &quot;ENG 4 &quot;, &quot;ENG 7 &quot;, &quot;ENG 3 &quot;, &quot;ENG 2 &quot;, &quot;ENG 22&quot;, &quot;ENG 20&quot;, &quot;ENG 24&quot;, &quot;ENG 32&quot;, &quot;ENG 25&quot;))
  </code></pre>
  <p>However my legend is not the way I want. Green part (high growth rate) should be on the left. I try the reverse in guides_legend but it did not work.
  Also I would like that the size of the legend occupies the length of the graph. I did not find any argumented in ggplot about legend lenght.</p>
  <p>Could someone help me? Or indicate if it is possible make these legend changes.</p>
  <p><a href="https://i.stack.imgur.com/5dNRw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5dNRw.png" alt="Differences in growth rate among genotypes for the highest growht (green) to lowest growth (red)" /></a></p>