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.

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
#
# Reproducible example.
#

library(ggplot2)
set.seed(42)
x  <- 1:20
y1 <- 2*x+3
y2 <- rep(y1,2) + rnorm(40,0,4)
y3 <- rep(y1,2) + rnorm(40,0,10)
xxx <- data.frame(x=rep(x,2),y1=y1,y2=y2,grp=factor(rep(c("a","b"),each=20)))
plotObj <- ggplot(xxx) + 
           geom_line(aes(x=x,y=y1)) +
           ylab("y")+
           geom_point(aes(x=x,y=y2),shape=20,col="blue",show.legend=TRUE) +
           geom_point(aes(x=x,y=y3),shape=3,col="red",show.legend=TRUE) +
           scale_colour_manual("Doesn't work",values=c("blue","red"),
                               labels=c("clyde","irving")) +
           facet_grid(cols=vars(grp))

Attachment: whatIwant.pdf
Description: Adobe PDF document

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to