Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing legend title ggplot

Tags:

r

ggplot2

I cannot seem to change the legend title without the legend splitting my shape and color into two separate legends. How can i change the combined legend title? The image is what the graph looks like.

ggplot(data = df, aes (x = factor(dminp,c("-3 to -1", "-1 to 1")), y = sum_diff,col = factor(dmin), shape = factor(dmin), group = factor(dmin)))+
xlab("Range of Difficulty Parameters for Screen Items") + ylab("Bias Due to Skip-Logic") +
  stat_summary(geom = "point",fun.y = "mean",size = 8, aes(shape = factor(dmin)))+
  stat_summary(geom = "point",fun.y = "mean",size = 8, aes(col = factor(dmin)))+
 scale_shape_manual(values = c(8,5)) + theme_bw() + scale_colour_manual(values = c("orange","purple"))+
  theme(panel.grid.major.x  =   element_blank(),
        panel.grid.major =   element_line(colour = "black",size=0.25))+ theme(legend.justification = "top") 

I have tried using labs(col = "what i want it to be named") but this adds a 2nd legend and splits shape/color.

like image 579
Greg Avatar asked Feb 14 '26 18:02

Greg


1 Answers

How about trying:

... +
scale_shape_manual(name="X",values = c(8,5)) + 
scale_colour_manual(name="X",values = c("orange","purple"))+
..

Here's an example:

ggplot(iris,aes(x=Sepal.Width,y=Sepal.Length,shape=Species,col=Species)) + 
geom_point()+
scale_color_manual(name="X",values=c("Blue","Orange","Red")) + 
scale_shape_manual(name="X",values=c(17,18,19))

enter image description here

like image 65
StupidWolf Avatar answered Feb 17 '26 08:02

StupidWolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!