ggplot2 : to change the title of legend

1,006 views
Skip to first unread message

Michel ARNAUD

unread,
Oct 11, 2013, 8:33:12 AM10/11/13
to ggp...@googlegroups.com
Hello
I don't arrive to change the title of the legend
My code is :
library(ggplot2)
ma <- max(General$AgeChangCat) ; mi <- min(General$AgeChangCat)
Test$Recrutement <- factor(Test$CadNonCadRecrut)
p <-
ggplot(Test, aes(x=factor(Cat1), y=AgeChangCat )) +
ylim(mi,ma) +
geom_point() +
geom_boxplot(aes(fill = Recrutement)) +
labs(title = "Age", x="catégorie", y="Age") +
theme(legend.position = c(0.1,0.9), legend.background = element_rect(colour = "black"))
p 


David Guy

unread,
Oct 11, 2013, 9:38:11 AM10/11/13
to Michel ARNAUD, ggplot2
Michel,

In order to change the legend title use:

p<- p + scale_fill_discrete(name="legendName")

In order to change the appearance of the title use:

p + theme(legend.title = element_text(colour="red", size=8, face="bold"))

I hope this helps.

David


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
David Guy, PhD
R Statistical Consulting Inc.
Flemington, NJ USA
 
Office: 908-237-5107
Cell:    917-941-5890
Fax:    908-284-0356
Skype: david.guy1213


Michel ARNAUD

unread,
Oct 11, 2013, 9:46:29 AM10/11/13
to David Guy, ggplot2
Merci/thanks David
Michel


Michel Arnaud
5 rue du Cannau
34000 Montpellier


2013/10/11 David Guy <rstatistica...@gmail.com>
Reply all
Reply to author
Forward
0 new messages