[R] Custom manual legend in ggplot2

Ronaldo Reis Júnior chrysopix at gmail.com
Wed Dec 9 14:52:29 CET 2015


Hi,

I'm trying to make a ggplot() graph with a custom legend, but without 
success, it is simple, I have somethink like this in traditional plot:

plot(y~x)
curve(equation1,lty=1)
curve(equation2,lty=2)
legend(x,y,legend=c("equation 1","equation 2"),lty=c(1,2),bty="n").

In my ggplot graph I have this sequence:

ggplot(data1, aes(x=x1, y=y1))+
     geom_point()+
     geom_smooth(method="glm", family="gaussian")+
     geom_smooth(aes(x=x1, y=y1,lty=2,data=data2, method="glm", 
family="gaussian")+
     theme(plot.title = element_text(lineheight=.8, face="bold"))+
     theme_bw()

The problem is that legend only work in automatic way, I try some option 
to add a manual legend in ggplot like the traditional legend() command. 
Anybody can help-me?

Thanks
Ronaldo


-- 

> Prof. Ronaldo Reis Júnior
|  .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional
| : :'  : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia
| `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil
|   `- Fone: (38) 3229-8192 | ronaldo.reis em unimontes.br
| http://www.ppgcb.unimontes.br/lecc | LinuxUser#: 205366


	[[alternative HTML version deleted]]



More information about the R-help mailing list