2012-10-19 2 views
1

와 기하 구조를 추가 이것은 논쟁의 여지가있는이 질문에 대한 후속 조치 :자체의 스케일과 전설

Add legend to ggplot2 line plot

Add vline to existing plot and have it appear in ggplot2 legend?

내가 자신의 독립을했을 그 음모에 기하 구조를 추가 할 데이터, 축척 및 범례 요소가 포함됩니다.

이것은 그래픽 원리의 문법 중 일부를 위반할 수 있지만 실제로는 전설에 나타나는 수직선 또는 수평선, 단일 점, 화살표 등의 요소를 원합니다.

다른 기하 구조 매핑에서 이미 눈금자가 사용되는 경우 어려움이 추가되는 것처럼 보입니다. 현재 vline와 연관 전설의 선 종류를 누락 생산

p<-qplot(data=iris, x=Petal.Width, 
     y=Sepal.Width, 
     colour=Species, 
     shape=as.factor(round(Petal.Length)), 
     linetype=as.factor(round(Sepal.Length)), 
     geom=c("line", "point")) 

p<-p+geom_vline(xintercept=0.75, aes(linetype="Setosa vs Versicolor")) 
p<-p+geom_vline(xintercept=1.75, aes(linetype="Versicolor vs Virginica")) 

print(p) 

:

여기

는 조리개를 사용하므로 꽤 예가 아니다.

enter image description here

답변

1
aes 전화에서 모두 xinterceptlinetype을 포함하도록 geom_vline 통화를 변경

. 지금은 linetype이 효과가 없습니다 (범례에 표시되지 않음).

qplot(data=iris, x=Petal.Width, 
     y=Sepal.Width, 
     colour=Species, 
     shape=as.factor(round(Petal.Length)), 
     linetype=as.factor(round(Sepal.Length)), 
     geom=c("line", "point")) + 
geom_vline(aes(xintercept=0.75, linetype="Setosa vs Versicolor")) + 
geom_vline(aes(xintercept=1.75, linetype="Versicolor vs Virginica")) 

## Warning messages: 
## 1: The shape palette can deal with a maximum of 6 discrete values because 
## more than 6 becomes difficult to discriminate; you have 7. Consider 
## specifying shapes manually. if you must have them. 
## 2: The shape palette can deal with a maximum of 6 discrete values because 
## more than 6 becomes difficult to discriminate; you have 7. Consider 
## specifying shapes manually. if you must have them. 
## 3: Removed 4 rows containing missing values (geom_point). 
## 4: The shape palette can deal with a maximum of 6 discrete values because 
## more than 6 becomes difficult to discriminate; you have 7. Consider 
## specifying shapes manually. if you must have them. 

enter image description here

관련 문제