2014-11-12 2 views
0

다음 ggplot을 가지고 있으며 범례와 geom_abline을 중간에 추가하려고합니다.Lineplot 범례 + ABLINE ggplot

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) 

내가 어떤 오류가 발생하고 있지 않다 그러나 거기에는 전설이되지도 abline입니다 : 이것은 플롯을 생성하기 위해 무슨 짓을

보라색 라인은 2013 PRODS위한 빨간색은 2014

입니다 이미지가 나타납니다. 플롯은

다음과 같습니다

enter image description here

어떤 도움은 매우 극명하게 될 것이다. aosmith의 조언으로 당

관련,

+0

최소한 하위 집합을 제공 할 수 있습니까? 귀하의 코드를 재현 할 수 있도록 데이터를 재현 할 수 있습니까? – cdeterman

+1

'geom_abline'에'h' 인수가 있다고 생각하지 않습니다. 'intercept'와'slope'를 모두 0으로 정의하거나'geom_hline'을 사용할 수 있습니다 (명확한 예제는 도움말 페이지 참조). '색'과 같은 미학이 '에이스 (Aes)'안에있을 때 당신은 전설을 얻습니다. – aosmith

답변

0

:

내가했던 다음과 같은 플롯 얻을 수있었습니다 :

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) 

줄거리는 다음과 같습니다

enter image description here

관련 문제