2017-11-07 3 views
1

나는 누적 그래프와 라인 그래프 나 선 그래프에 대한 범례를 추가 할디스플레이 전설 - 스택 막 대형 및 라인

ggplot() + 
     geom_bar(data=smr2, aes(x=Pract, y=value, fill=variable), stat='identity') + 
     theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + 
     geom_line(data=summarised[,1:3], aes(x=Pract,y=YTDTarget, group=1),size = 1) + 
     geom_point(data=summarised[,1:3], mapping = aes(x = Pract, y = YTDTarget),size=2.5)+ 
     geom_text_repel(data=summarised[,1:3], aes(x=Pract,y=YTDTarget,label=YTDTarget), size = 5) 

의 조합 인 ggplot을 보유하고 있습니다. 그러나 부분 group=1이 이것을 방지하는 것 같습니다.

내가 만든 그래프는 또한

enter image description here로, 실제로 달성에 대해 대상 (선 그래프)를 비교하기위한 "실제는" 이 그래프는 (바 스택에 변수에서 전설의 이름을 변경할 도와주세요입니다).

답변

3

이 시도하십시오

geom_line에 더미 변수를 추가 (전설에 추가 - 나는 linetype를 사용하고 있는데이 경우).

geom_line(data = summarised[,1:3], 
      aes(Pract, YTDTarget, group = 1, linetype = ""), 
      size = 1) 

전설의 이름이 음모에 labs()를 추가 변경합니다.

labs(fill = "Actuals", 
    linetype = "My Line Name") 
관련 문제