1

I have a problem adding geom_vline legends when I already have very well defined geom_line legends my code is as follows:

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

As a Result I get:

geom line and geom vline plot

Where CODT id the time period en Tre7 is a dummy variable for treated and controls, TNA is BirthRates of this two groups.

My question is how can I get a nice legend for geom_vline with the label "27F" that does not interfere with geom_line legends? I have tried with show.legend=TRUE and Show_guide=TRUE but nothing is working.

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
Kota
  • 11
  • 1
  • Hi Kota. Please provide a reproducible example - i.e., give some sample data (ideally in the form of a `dput`) so that we can try to reproduce the problem and test possible solutions. – iod Nov 01 '18 at 16:00
  • As a guess, I would say you need to include `color` in the `geom_vline` inside an `aes`. – iod Nov 01 '18 at 16:02
  • See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Nov 01 '18 at 16:29

0 Answers0