1

当我已经有非常明确的 geom_line 图例时,我在添加 geom_vline 图例时遇到问题,我的代码如下:

g1=ggplot(M7, aes(x =CODT, y =TNA, group =Tre7))
g1=g1+geom_line(aes(color=Tre7, linetype=Tre7), size=0.8)
g1=g1+scale_color_manual(values=c("#7FCCE7", "#DC693F"), name  ="Groups", breaks=c("0", "1"),labels=c("Control", "Treated"))
g1=g1+scale_linetype_manual(values=c("solid", "dotdash"), name  ="Groups", breaks=c("0", "1"),labels=c("Control", "Treated"))
g1=g1+geom_vline(xintercept=122,linetype="solid", size=1, color="#9B9FA1")
g1=g1+labs(x="Time Period", y="Births by 1000 people")
g1=g1+ggtitle("Mean of Birth Rates for Treated and Control")+scale_x_continuous(breaks=c(0,24,48,72,96,120,144,168,192), labels=c(2000, 2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016))+theme_economist_white()
g1

结果我得到:

geom line 和 geom vline 图

其中 CODT id 时间段 en Tre7 是治疗组和对照组的虚拟变量,TNA 是这两组的出生率。

我的问题是如何获得一个不错的 geom_vline 图例,标签为“27F”,不会干扰 geom_line 图例?我曾尝试使用 show.legend=TRUE 和 Show_guide=TRUE 但没有任何效果。

4

0 回答 0