Legend placement, ggplot, relative to plotting region

后端 未结 4 696
日久生厌
日久生厌 2020-11-28 05:25

Problem here is a bit obvious I think. I\'d like the legend placed (locked) in the top left hand corner of the \'plotting region\'. Using c(0.1,0.13) etc is not an option fo

4条回答
  •  天涯浪人
    2020-11-28 05:56

    To expand on the excellend answers above, if you want to add padding between the legend and the outside of the box, use legend.box.margin:

    # Positions legend at the bottom right, with 50 padding
    # between the legend and the outside of the graph.
    theme(legend.justification = c(1, 0), 
        legend.position = c(1, 0),
        legend.box.margin=margin(c(50,50,50,50)))
    

    This works on the latest version of ggplot2 which is v2.2.1 at the time of writing.

提交回复
热议问题