Please excuse the very simple request, but I'm new to ggplot and can't
find how to do this anywhere in the help or mailing list.
I have a geom_rect() plot showing two series of rectangles for each x
value:
df<-data.frame(x=c(1:5),y1=c(1:5),y2=c(8:12))
ggplot(df,aes(xmin=x,xmax=x+1))
+geom_rect(aes(ymin=y1,ymax=y1+1),fill="blue")
+geom_rect(aes(ymin=y2,ymax=y2+1), fill="red")
and would like to add a legend to this plot (eg. showing blue="series
1", red="series 2").
However, I can't do this simple task! I've tried many combinations of
possibilities, such as using the fill aesthetic [eg.
geom_rect(aes(..., fill="blue"))] and using scale_colour_manual, but
nothing I've tried works.
I'm sure this is down to my unfamiliarity with ggplot, but I've had to
give up. So any suggestions would be gratefully received!
Thanks very much.
--
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
My advice is to always think about the data - what variable are you
mapping to the fill colour? If that variable doesn't exist in your
data, it may be suggesting that you should reshape the data so that it
is.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/