I am trying to create a theme for ggplot, which I can then use for all my graphs and get them both pleasant and pleasant and homogeneous. I want to move the legend from its current position, vertically centered on the right, to be aligned with the top of the graph on the right, as shown by the red arrow below.

I can not understand. I can force it to be positioned inside the plot using legend.position , but if I then make legend.justification = c(0.0, 1.0) , it pops the legend outside the area that it is plotting, and it completely turns off. I know that I could do this individually for each graph, combining with grobs and gtables for each individual graph, but I do not want to do this every time I draw a graph.
Is there any way to do this using theme ?
r ggplot2
Jack aidley
source share