Re: Customising Legend

20 views
Skip to first unread message

Dennis Murphy

unread,
Nov 22, 2012, 3:55:42 PM11/22/12
to ADP, ggp...@googlegroups.com
Hi:

This is a little extreme, but here's a toy example. Basically, you need to reduce the legend.key.height theme element. 

 DF <- data.frame(gp = factor(rep(LETTERS[1:3], each = 20)),
                   x = seq(20),
                   y = 0.5 + rep(0:2, each = 20) + 
                             0.3 * rep(seq(20), 3) + rnorm(60))
library('ggplot2')
library('grid')   # needed for the unit() function call below

ggplot(DF, aes(x, y, color = gp)) +
    geom_point() + 
    geom_smooth(method = lm, se = FALSE) +
    theme(legend.position = c(0.15, 0.82), 
              legend.key.height = unit(0.5, "mm"))

Dennis



On Wed, Nov 21, 2012 at 4:56 PM, ADP <nicholas...@gmail.com> wrote:
Does anyone have a workaround for adjusting the legend, to reduce the amount of white-space between legend items, without reducing the size of the font used.

In my work, I quite often place the legend inside the plot area, so that the outer bounds are preserved (for consistency), and, in this one instance, I want to reduce the footprint that the legend occupies within the main plot area.

Cheers.



--
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

Reply all
Reply to author
Forward
0 new messages