[R] Custom manual legend in ggplot2

Ronaldo Reis Júnior chrysopix at gmail.com
Wed Dec 9 16:11:23 CET 2015


Thanks,

Now its work, but I dont get to change te legend position. Look:


ggplot(data1, aes(x=x1, y=y1))+
     geom_point()+
     geom_smooth(method="glm", family="gaussian",aes(linetype="equation1"))+
     geom_smooth(aes(x=x1, y=y1, linetype="equation2"),data=data2, 
method="glm", family="gaussian")+
     scale_linetype_manual(values = 
c("solid","dashed"),name="Equations",labels=c("Equation 1","Equation 
2"),guide="legend")+
     theme(plot.title = element_text(lineheight=.8, 
face="bold"),legend.position="top")+
     theme_bw()

Now the legend work, but the argument legend.position="top" in theme() 
function dont work. I try to change the order of commands, but without 
effects.

Any idea?

Thanks
Ronaldo

Em 09-12-2015 12:10, Giorgio Garziano escreveu:
> Try to look at the link:
>
> http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/
>
>
> Also consider:
>
> help(theme)
>
> legend.background    background of legend (element_rect; inherits from rect)
> legend.margin   extra space added around legend (unit)
> legend.key background underneath legend keys (element_rect; inherits from rect)
> legend.key.size size of legend keys (unit; inherits from legend.key.size)
> legend.key.height    key background height (unit; inherits from legend.key.size)
> legend.key.width     key background width (unit; inherits from legend.key.size)
> legend.text     legend item labels (element_text; inherits from text)
> legend.text.align    alignment of legend labels (number from 0 (left) to 1 (right))
> legend.title    title of legend (element_text; inherits from title)
> legend.title.align   alignment of legend title (number from 0 (left) to 1 (right))
> legend.position the position of legends ("none", "left", "right", "bottom", "top", or two-element numeric vector)
> legend.direction     layout of items in legends ("horizontal" or "vertical")
> legend.justification anchor point for positioning legend inside plot ("center" or two-element numeric vector)
> legend.box arrangement of multiple legends ("horizontal" or "vertical")
> legend.box.just justification of each legend within the overall bounding box, when there are multiple legends ("top", "bottom", "left", or "right")
>
> --
>
> GG
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help em 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.
>

-- 
1

> 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