2014-11-05 3 views
1

세 가지 모양 (작은 원, 큰 원 및 십자형)으로 산점도를 만들려고합니다. 내가 원, 삼각형, 사각형을 얻을ggplot의 모양에 대한 정의 (기본값 사용 안 함)

AData=as.data.frame(cbind(x=rnorm(5, 10, 1),y=rnorm(5,10,1))) 
AData["Type"] = rep(1,dim(AData)[1]) 
BData=as.data.frame(cbind(x=rnorm(5, 20, 1),y=rnorm(5,20,1))) 
BData["Type"] = rep(2,dim(BData)[1]) 
CData=as.data.frame(t(c(0,0,3))) 
colnames(AData) = c("Ankle.dif", "Knee.dif", "Type") 
colnames(BData) = c("Ankle.dif", "Knee.dif", "Type") 
colnames(CData) = c("Ankle.dif", "Knee.dif", "Type") 
dataFramePlot = rbind(AData, BData, CData) 
ggplot(dataFramePlot, aes(x=Ankle.dif, y=Knee.dif)) + geom_point(aes(shape = factor(Type))) 

: 나는 모양을 지정하는 방법을 알아낼 수 없습니다 것을 제외하고, 내가 원하는 거의 무엇을 요점을 얻을 수 있어요

여기,하지만 세 가지 유형에 대해 작은 원, 큰 원 및 크로스바를 지정하는 것을 선호합니다. 어떤 아이디어? 감사!

답변

1

여기는 scale_shape_manual을 사용하는 편도입니다. 모양의 경우 많은 장소에서 자세한 정보를 찾을 수 있습니다. 여기에 link이 있습니다. 아래 코멘트에서 OP가 요청 했으므로 필자는 전설을 수정했습니다.

ggplot(dataFramePlot, aes(x=Ankle.dif, y=Knee.dif)) + 
geom_point(aes(shape = factor(Type)))+ 
scale_shape_manual(name = "Data", 
        values=c(20, 19, 3), 
        breaks=c("1", "2", "3"), 
        labels=c("First data", "Second data", "Third data")) 

enter image description here

+0

감사 @jazzurro : 대신 목록의 "1", "2", 및 "3", 나는 세 개의 문자열을 만들 수 있도록 나는, 특히 계수 (유형) 레이블을 변경 할 방법 레이블? –

+0

@JosephHudson 숫자 대신 원하는 레이블은 무엇입니까? – jazzurro

+0

감사합니다. @ jazzurro : "첫 번째 데이터", "두 번째 데이터", "세 번째 데이터"라는 세 개의 레이블을 사용하고 싶습니다. –