Changing ggplot2 legend title without altering graphical parameters
ggplot2, graphics, r
Solution
You have to set the same title for all `aes()` attributes you have used, for example, using function `labs()`.
gp1 + scale_colour_manual(values=c("red","blue"))+
labs(colour="NEW TITLE",linetype="NEW TITLE",shape="NEW TITLE")
Problem
I have found many topics about the legend title with ggplot2 but after a couple of hours I have not been able to handle my situation. Here is the dataset: ``` > dat FACTOR1 FACTOR2 lsmean lower.CL upper.CL 1 A aa 26.2 25.6 26.8 2 B aa 24.8 23.9 25.7 3 A bb 26.0 25.2 26.7 4 B bb 24.9 23.9 25.9 5 A cc 24.4 23.9 24.8 6 B cc 23.9 22.9 25.0 7 A dd 24.9 24.3 25.6 8 B dd 23.2 22.3 24.0 ``` And the graphic of interest: ``` gp0 <- ggplot(dat, aes(x=FACTOR2, y=lsmean, group=FACTOR1, colour=FACTOR1)) ( gp1 <- gp0 + geom_line(aes(linetype=FACTOR1), size=.6) + geom_point(aes(shape=FACTOR1), size=3) + geom_errorbar(aes(ymax=upper.CL, ymin=lower.CL), width=.1) + geom_errorbar(aes(ymax=upper.CL, ymin=lower.CL), width=.1) ) ``` If I use `scale_colour_manual()` to change the legend title then I get an unexpected additional legend: ``` gp1 + scale_colour_manual("NEW TITLE",values=c("red","blue")) ``` I suppress this additional legend with `scale_"aes"_manual("guide=none", values=...)` but I don't understand how to control the parameters (the style of points and lines): ``` gp1 + scale_colour_manual("NEW TITLE",values=c("red","blue")) + scale_shape_manual(guide = 'none', values=c(1,2)) + scale_linetype_manual(guide = 'none', values=c(1,3)) ``` Please how to reproduce the first plot with and only with a new legend title ?