由组创建的ggplot图例无法编辑

时间:2018-03-29 03:30:39

标签: r ggplot2

我试图找出如何控制第一个ggplot行中group参数创建的图例。我喜欢使用group,因为稍后使用geom_ribbon可以使置信区段变得更加平滑。如果我只使用color = tx.f,则置信区域看起来非常奇怪,并且要么是锯齿状的,要么是有一个oitline。使用group = tx.f选项的唯一问题是它创建了另一个我似乎无法摆脱或编辑的图例。有关如何编辑此图例的任何线索?我已经尝试了很多东西,但我似乎无法编辑这个传奇或将其从我的情节中删除。

stai_plot<-ggplot(aes(x = cwk, y = estimate__, group=tx.f, colour=tx.f, 
linetype=tx.f), data = plt_dat_stai) +
geom_point(aes(y = stai), data = subj_marginals_stai, 
         position = position_dodge(width=0.2),
         alpha = 0.4) + 
geom_line(aes(cwk,estimate__),size=1)+
geom_ribbon(aes(ymin=lower__,ymax=upper__), alpha=.1, colour=NA)+
scale_y_continuous(name = "STAI", limits = c(30,75))+
theme_minimal()+
labs(color='Treatment\nType', group="Treatment Type") +
scale_x_continuous(name="Treatment Week", breaks=c(-3,0,3), labels=c("Week 1", "Week 3", "Week 6"))+
scale_color_manual(labels = c("Waitlist", "Integrative"),values=c("black",  "blue"))
stai_plot

我得到的结果如下:

See that there are two legends

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您要删除线型图例。如果要删除单个图例,可以使用guide()指定。在您的情况下,将其添加到您的绘图代码的末尾应该解决它。

+guides(linetype = FALSE)