0

I am building a grid of geom_treemaps. There are 2 plots, side by side in one row. I want to have the legend (a continuous color gradient) span underneath the length of the entire window. To do this, I am extracting the legend from another geom with get_legend(plot) and drawing it in its own viewport. When I draw the legend, it shows no regard for the constraints of the viewport. I can adjust the legend.key.width parameter in the theme() of the plot I extracted the legend from, but that process is very manual. Is there a way to coerce this legend to fit (specifically lengthwise) into a viewport?

Thank you for any responses.

jhbok
  • 1
  • 1
  • This previous answer may provide some guidance. https://stackoverflow.com/questions/43686157/how-do-i-properly-resize-all-aspects-of-a-ggplot-in-r-including-the-legend?rq=1 – Mostafa Lotfi Jul 31 '19 at 19:47
  • 4
    Consider adding a small example dataset and the code you are using, often called a reproducible example, so folks can see the problem and possibly offer solutions. You can see some ideas for how to do this [in this link](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – aosmith Jul 31 '19 at 19:50
  • I saw a plot in Wilke's Fundamentals of Data Visualization that seemed like it might be a simpler version of what you may be trying to do ([Figure 20.12](https://serialmentor.com/dataviz/redundant-coding.html#fig:temp-ridgeline-colorbar)). That plot is made using some **cowplot** functions. You can explore the code [for that chapter/figure on GitHub](https://github.com/clauswilke/dataviz/blob/master/redundant_coding.Rmd). – aosmith Jul 31 '19 at 19:53

0 Answers0