[R] Adding a legend to a (multi-facet) plot produced by ggplot().
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Dec 1 15:03:12 CET 2019
See if this is it. The standard trick is to reshape the data from wide
to long, see the SO post . Then add a scale_shape_* layer to the plot.
yyy <- cbind(xxx, y3 = y3)
long <- reshape2::melt(yyy, id.vars = c("x", "y1", "grp"))
ggplot(long, aes(x, y = value, colour = variable, shape = variable)) +
geom_line(aes(y = y1)) +
Hope this helps,
Às 00:04 de 01/12/19, Rolf Turner escreveu:
> I have been struggling to add a legend as indicated in the subject line,
> with no success at all. I find the help to be completely bewildering.
> I have attached the code of what I have tried in the context of a simple
> reproducible example.
> I have also attached a pdf file of a plot produced with base graphics to
> illustrate roughly what I am after.
> I would be grateful if someone could point me in the right direction.
> Rolf Turner
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help