简体   繁体   English

更改图例标题ggplot

[英]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.我曾尝试使用 labs(col = "what i want it to be named") 但这会添加第二个图例并拆分形状/颜色。

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))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM