Greg
Greg

Reputation: 41

Changing legend title ggplot

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.

Upvotes: 3

Views: 3736

Answers (1)

StupidWolf
StupidWolf

Reputation: 46968

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

Upvotes: 3

Related Questions