r - Lineplot legend + ABLINE ggplot -


i have following ggplot , trying add legend , geom_abline @ median.

purple line 2013 prods , red 2014

this did generate plot:

ggplot(prods[year==2013,], aes(x = date, y = prod, group = som)) +   geom_line(lwd = 1.3, colour = "purple") +  ylab("actual productivity") + theme(axis.title.x=element_blank()) +  geom_line(data=prods[year==2014,], aes(x = date, y = prod, group = som),lwd = 1.3, colour = "red") +  geom_abline(data = prods,h=median(prod))+  scale_color_manual("period", values = c("purple","red"), labels = c("2013","2014")) +  facet_wrap(~ som) 

i not getting error there no legend nor abline popping on image. plot looks

this:

enter image description here

any highly appreciated.

regards,

as per aosmith's advice:

i did following , able following plot:

ggplot(data=prods,aes(date)) +    geom_line(data=prods[year==2013,],aes(y=prod, colour="red"),lwd = 1.3,) +       geom_line(data=prods[year==2014,],aes(y=prod, colour="blue"),lwd = 1.3) +      geom_hline(data=prods, aes(yintercept = median(prod))) +   scale_colour_manual(name="period",values=c("blue","red", "black"), labels = c("2014","2013", "median")) +    ylab("actual prod") + xlab(" ") +    theme(axis.title.y = element_text(size = 15, vjust=0.3)) +   facet_wrap(~ som) 

plot looks this:

enter image description here


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -