I´m doing a graph with linear regression lines compared to loess-lines and robust regression lines in different colors and I would like to add a legend describing which color is which line. How can I do this?
library(ggplot)
library(MASS)
data(diamonds)
p<ggplot(diamonds,aes(x,price))+facet_grid(cut~color)+geom_point(color="grey")+geom_smooth(color="Red")+geom_smooth(method="lm",formula=y~x,color="blue")+geom_smooth(method="rlm",color="green")
p
Also,How can I maintain the individual x and y axes in each of the facets. By doing:
p+opts(panel.grid.minor=theme_blank(),panel.grid.major=theme_blank(),panel.background=theme_blank(),axis.line=theme_segment())
I´m only left with the border axis, nt for the individual graphs? I admit it looks very nice, but a referee specifically asked to have these axes present..
Best,
//M
data(diamonds)
p<-ggplot(diamonds,aes(x,price))+facet_grid(cut~color)+geom_point(color="grey")+geom_smooth(aes(color="LOESS"))+geom_smooth(method="lm",formula=y~x,aes(color="LM"))+geom_smooth(method="rlm",aes(color="RLM"))
p+scale_colour_manual("",c("LOESS"="red","LM"="blue","RLM"="green"))
But the second question regarding plotting of both the x and y axis for each of the individual faceted plots I havent found a solution to.. Any ideas would be greatly appreciated..
//M
Include color as an aesthetic, latter map using a scale_discrete?
Hope this helps,
fernando
library(ggplot2)
library(MASS)
data(diamonds)
p <- ggplot(diamonds,aes(x,price)) + facet_grid(cut~color) +
geom_point(color=I("grey")) + geom_smooth(aes(colour="Loess")) +
geom_smooth(method="lm",formula=y~x, aes(colour="Linear
regression")) +
geom_smooth(method="rlm", aes(colour="Robust linear regression")) +
scale_colour_discrete(name = "Method", legend = TRUE)
p
-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
moleps
Enviado el: jueves, 24 de junio de 2010 15:13
Para: ggplot2
Asunto: add legend for each geom
Dear All,
p+opts(panel.grid.minor=theme_blank(),panel.grid.major=theme_blank(),panel.b
ackground=theme_blank(),axis.line=theme_segment())
Best,
//M
--
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
It's not currently possible with facet_grid. And it's not high on my
to do list, as it basically adds no extra information to the plot,
just takes up a whole lot of extra space - I would argue with the
reviewer on that point.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/