legend at specific position outside the graphic area

21 views
Skip to first unread message

Joan Cardona

unread,
Oct 17, 2014, 2:28:31 AM10/17/14
to ggp...@googlegroups.com
Does anybody know how to place the legend at, for example, bottom left corner outside the graphic area? Is it, actually, possible?

I only know how to put it at the bottom, but it always appears centered (theme's legend.position="bottom"). I mean, it does'nt exist the "bottomleft" value or something similar. Other values of position (i.e. legend.position=c=(1,0)) shows the legend inside the graphic area, and this is not what I want. Any idea?

Ben Bond-Lamberty

unread,
Oct 22, 2014, 6:57:06 AM10/22/14
to Joan Cardona, ggplot2
It looks like legend.position accepts negative values, so combining
that with plot.margin should get you the desired effect, I think, e.g.

> last_plot() + theme(legend.position = c(-0.05, -0.05), plot.margin=unit(c(0.5,0.5,1.5,0.5),"cm"))

Ben
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages