title: Is it possible to position the legend to the top right of a ggplot in R?
body: <p>I am trying to create a theme for ggplot that I can then use for all my graphs and getting them looking both nice and nice and uniform. I want to move the legend from its current position vertically centred on the right to being aligned with the top of the graph on the right, as indicated by the red arrow below.</p>
  
  <p><img src="https://i.stack.imgur.com/stJ7w.jpg" alt="Desired legend movement"></p>
  
  <p>I cannot figure it out. I can get it to position <em>inside</em> the plot by using <code>legend.position</code> but if I then do <code>legend.justification = c(0.0, 1.0)</code> it pushes the legend outside of the area it plots and it gets cut off completely. I know I could do it individually for each graph by messing around with grobs and gtables for each individual graph but I don't want to have to do that every time I plot a graph.</p>
  
  <p>Is there anyway to do this with a <code>theme</code>?</p>