2013-07-26 2 views
1

저는이 분야에서 처음으로 질문을하는 것이 아니라는 것을 알고 있습니다. 그러나 나는이 특정 문제에 대한 해결책을 찾아 내지 못했습니다. 여기 내 문제에 대한 철저한 사례가 있습니다. ggplot2 범례 - geom_point와 geom_abline을 함께 슬래시

data<-data.frame(Est=c(1:20,1:20),Measured=c(1:5,5:9,1:6,3:6,1:6,3:6,1:4,4,4:8),variable=c(rep("Plot1",20),rep("Plot2",20))) 

p<-ggplot(data,aes(y=Est,x=Measured,shape=variable)) 
p<- p + geom_point(stat="identity") +coord_fixed(xlim=c(0,25),ylim=c(0,25)) + theme_bw() 

p #If you plot the figure at this point, the points stand alone in the legend 
p<-p+ geom_abline(intercept=0,slope=1,aes(linetype="1:1",color="1:1"),show_guide=TRUE) 

p # Once the geom_abline is added, there are lines through the points. :(

p<-p+scale_color_manual(name="Lines", 
         values=c("1:1"="black")) 
p<- p + scale_linetype_manual(name="Lines", 
           values=c("1:1"=2))    

p<-p + scale_shape_manual(values=c(0,20), name = "") 

p<- p+xlab(expression(paste("Measured volume(",ducks^{3},"",ha^{-1},")",sep=""))) 
p<-p+ ylab(expression(paste("Estimated volume (",ducks^{3},"",ha^{-1},")",sep=""))) 

당신이 볼 수 있듯이

는 점에 대한 전설은 (실제로 줄 생각) 슬래시를 포함하고 정말 포인트 혼자라고 선호 할 것입니다.

예제 코드에는 단 하나의 선 및 선 종류 만 있지만 실제로 만든 그림에는 다양한 색상과 선 종류가있는 5 개의 다른 선이 포함되어 있으므로 색상 및 선 종류가있는 여러 geom_abline 호출을 포함 할 수있는 솔루션이 필요합니다. 지정된.

그리고 공부 정말 재미있을 것입니다하지만 아니, 난 정말, 오리 아무것도의 양을 측정 아니에요 ...

답변

5

재정의 미적 매핑 :

p + guides(shape = guide_legend(override.aes = list(linetype = 0))) 

난 항상 끝 미학을 무시하려고 애 쓰지만, 어째서 직감이 잘못되었는지는 알 수 없다.

+0

Perfect! 고마워, 조란! – Nan

관련 문제