[R] Adding a legend to a (multi-facet) plot produced by ggplot().
Rolf Turner
r@turner @end|ng |rom @uck|@nd@@c@nz
Mon Dec 2 05:19:24 CET 2019
On 2/12/19 5:08 pm, Rui Barradas wrote:
> Hello,
>
> Here are two ways of drawing the lines black and at the same time
> removing the lines in the legend. The second way is more idiomatic.
>
>
> 1. Override the colour setting in the ggplot call when drawing the lines:
>
> geom_line(aes(y = y1), colour = "black") +
>
>
> 2. Don't set the colour aesthetic in the initial ggplot call. It will be
> needed only to draw the points, so set it in geom_point(). Though it
> doesn't influence the lines' colour and the lines in the legend, the
> same principle applies to shape = variable so I have moved it to
> geom_point().
>
> The complete instruction becomes:
>
>
> ggplot(long, aes(x, y = value)) +
> geom_line(aes(y = y1)) +
> geom_point(aes(colour = variable, shape = variable)) +
> scale_colour_manual("Doesn't work",values=c("blue","red"),
> labels=c("clyde","irving")) +
> scale_shape_manual("Doesn't work",values=c(16,3),
> labels=c("clyde","irving")) +
>
> facet_grid(cols=vars(grp))
>
>
>
> Hope this helps.
Boy did it *ever*!!! Perfect. Thank you *HUGELY*!!!
cheers,
Rolf
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list