You can change the settings of scale_fill to match those of scale_color, which
will cause the two legends to be collapsed into one. Just add1
scale_fill_discrete( name = 'supplement',
breaks = c( 'OJ', 'VC' ),
label = c( 'orange juice', 'ascorbic acid' ))
to your final p
Best,
Ista
label = c( 'orange juice', 'ascorbic acid' ) ) +
scale_fill_discrete( name = 'supplement',
How could I have found out that the source of the second legend was geom_smooth()?
MK
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
geom_smooth() was the source only because you mapped the fill
aesthetic to supp inside its aes(). By default, every mapped,
non-positional aesthetic (e.g, fill, color, size) generates its own
legend. A variable is mapped to an aesthetic inside an aes() call;
aesthetics can be set to constant values outside of aes(); e.g., size
= 3.
To merge two legends, they need to have the same legend title and the
same breaks, values and labels; that's usually done with
scale_aesthetic_manual(), as Ista pointed out (where 'aesthetic' is a
placeholder for the actual aesthetic).
HTH,
Dennis