title: ggplot2: Add legend and associated legend title to barplot
body: <p>I have the following barplot which was produced from <a href="https://stackoverflow.com/questions/41549596/how-to-make-a-grouped-barplot-for-a-factor-with-many-levels/41550321#41550321">the data-set 'temp'</a> (the data is situated at the bottom of this stack overflow page and can also be found by following this link above). </p>
  
  <p><a href="https://i.stack.imgur.com/bNHiD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bNHiD.png" alt="enter image description here"></a></p>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>The objective is to add a legend to the right hand side of the barplot (above) titled as <strong>Canopy Type</strong> with labels denoting <strong>Under Canopy</strong> and <strong>Open Canopy</strong>. </p>
  
  <p>I tried using scale_colour_manual as given in another stackoverflow answer but I can't get a legend to show up. </p>
  
  <p>If anyone can help, then many thanks in advance</p>
  
  <p><strong>The code to generate the barplot was:</strong></p>
  
  <p>Assuming you want to plot means of Canopy_Index for each Under_Open, Topography cell, you can form means first:</p>
  
  <pre><code> df.means &lt;- aggregate(Canopy_Index ~ Under_Open + Topography, df.melt, mean)
  </code></pre>
  
  <p>Then, plot df.means using the code from your question:</p>
  
  <pre><code>  ggplot(df.means, aes(x = Topography, y = Canopy_Index, 
                       fill = factor(Under_Open), group = Under_Open)) +
    geom_bar(stat = "identity", position = "dodge") +
    scale_fill_discrete(name = "Topographical Feature", 
                        breaks = c("Under_tree", "Open_Canopy"),
                        labels = c("Under Canopy", "Open Canopy")) +
    xlab("Topographical Feature") + ylab("Canopy Index") +
    scale_colour_manual("Canopy Type", values = c("red", "blue")) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1), 
          text = element_text(size=14)) + 
    theme(panel.background = element_blank(), 
          panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          panel.border = element_blank()) + 
    theme(axis.line.x =     element_line(color="black", size = 0.8),
          axis.line.y = element_line(color="black", size = 0.8)) 
  </code></pre>