is it possible to create a plot with both lines and points and have
only one legend?
Currently, I use the following to create my plot:
p <- ggplot(molten.data, aes(x=max_errors, y=value, colour=mapper,
group=mapper, shape=mapper), summary="asdf")
p <- p + facet_wrap(~ variable, scales="free_y", ncol=1)
p <- p + geom_line()
p <- p + geom_point()
p <- p + scale_x_discrete(name='max error')
p <- p + scale_y_continuous('')
p <- p + scale_colour_discrete('read mapper')
p <- p + theme_bw()
The plot looks allright, there are markers at my data points and
lines connecting them. However, there is a key for both data points
with the right shape (all black) and one for the lines with the right
color (but the wrong shape). Is there a way to "merge" the legend?
Can you please provide a reproducible example by including some of
your data with dput?
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
On Feb 19, 4:22 am, Manuel Holtgrewe <zyklenf...@googlemail.com>
wrote:
> Hi,
>
> is it possible to create a plot with both lines and points and have
> only one legend?
Legend merging happens automatically when they have the same title and
level labels (it may be more complicated than that, but this is the
general idea; see Section 6.5, p111 of the ggplot2 book, if you have a
copy of that).
> Currently, I use the following to create my plot:
>
> p <- ggplot(molten.data, aes(x=max_errors, y=value, colour=mapper,
> group=mapper, shape=mapper), summary="asdf")
> p <- p + facet_wrap(~ variable, scales="free_y", ncol=1)
> p <- p + geom_line()
> p <- p + geom_point()
> p <- p + scale_x_discrete(name='max error')
> p <- p + scale_y_continuous('')
> p <- p + scale_colour_discrete('read mapper')
You changed the name of the colour scale, but not the shape scale.
Change the shape scale as well and they should merge. (Untested, since
you don't have a self-contained example).
p <- p + scale_shape_discrete("read mapper")
> p <- p + theme_bw()
>
> The plot looks allright, there are markers at my data points and
> lines connecting them. However, there is a key for both data points
> with the right shape (all black) and one for the lines with the right
> color (but the wrong shape). Is there a way to "merge" the legend?
--Brian Diggs