title: How to remove the legend or make transparent while keeping its space in ggplot?
body: <p>This question has been answered here: <a href="https://stackoverflow.com/questions/42438450/make-legend-invisible-but-keep-figure-dimensions-and-margins-the-same">Make legend invisible but keep figure dimensions and margins the same</a> and <a href="https://stackoverflow.com/questions/42438450/make-legend-invisible-but-keep-figure-dimensions-and-margins-the-same">Make legend invisible but keep figure dimensions and margins the same</a>, but the solutions provided do not work for me so far. The aim is to make the legend invisible or white while keeping the space it takes in the graph.</p>
  <p>I still get the outer box lines of the legend on the right, and I am not sure how to remove them. Can someone help please?</p>
  <p><a href="https://i.stack.imgur.com/wca6g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wca6g.png" alt="enter image description here" /></a></p>
  <p>Here is the code:</p>
  <pre><code>ggplot(l, aes(x=year, y=annual_chg, fill=income,color=income)) +
    geom_col(position = &quot;identity&quot;, alpha = 1/2,colour= &quot;black&quot;) +  
    facet_wrap(~Class,nrow=1)+
    theme_classic()+xlab(NULL)+ylab(NULL)+
    theme(
      legend.text = element_text(color = &quot;white&quot;),
      legend.title = element_text(color = &quot;white&quot;),
      legend.key = element_rect(fill = &quot;white&quot;)) + 
    guides(fill = guide_legend(override.aes= list(alpha = 0)),
           colour = guide_colorbar(override.aes = list(alpha=0)))
  </code></pre>
  <p>Here is the data:</p>
  <pre><code>df=structure(list(year = c(2018, 2018, 2018, 2018, 2018, 2018, 2018, 
                              2018), annual_chg = c(-0.66, 0.34, 0.59, 1.54, -0.26, 0.49, 0.66, 
                                                    1.62), Class = structure(c(4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L), .Label = c(&quot;Upper-middle class&quot;, 
                                                                                                                           &quot;Middle class&quot;, &quot;Skilled working class&quot;, &quot;Low-skilled working class&quot;
                                                    ), class = &quot;factor&quot;), income = c(&quot;gross income&quot;, &quot;gross income&quot;, 
                                                                                     &quot;gross income&quot;, &quot;gross income&quot;, &quot;net income&quot;, &quot;net income&quot;, &quot;net income&quot;, 
                                                                                     &quot;net income&quot;)), row.names = c(NA, -8L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, 
                                                                                                                                       &quot;data.frame&quot;))
  </code></pre>