2017-10-18 4 views
1

다른 색상으로 위도와 경도 값을 플로팅합니다. 플로팅 된 포인트에 시퀀스 번호 (아래 그림과 같이 1,2,3 ...)를 넣을 수있는 방법이 있습니까? 한 사람이 한 경도와 위도의 쌍에서 다른 한 쌍으로 변하는 것을보고 싶습니다.R Plot의 데이터 포인트에 시퀀스 번호 입력

require(ggplot2) 
df <- data.frame(x = rpois(10, 5), y = rpois(10, 5), group = 1:10) 
g <- ggplot(df, aes(x = x, y = y, color = as.factor(group))) 
g <- g + geom_segment(aes(xend=c(tail(x, n=-1), NA), 
         yend=c(tail(y, n=-1), tail(y, n = 1))), 
        arrow=arrow(length = unit(0.5, "cm"))) 
g <- g + theme_bw() + theme(legend.position="none") + xlab("longitude") + 
ylab("latitude") 
g 

plot

답변

0

이보십시오. 열쇠는 label이며, geom_text입니다. 나는 또한 화살과 텍스트 사이의 중복을 피하기 위해 jitter 함수를 사용했습니다.

library(ggplot2) 
df <- data.frame(x = rpois(10, 5), y = rpois(10, 5), group = 1:10) 
g <- ggplot(df, aes(x = x, y = y, color = as.factor(group),label = group)) 
g <- g + geom_segment(aes(xend=c(tail(x, n=-1), NA), 
          yend=c(tail(y, n=-1), tail(y, n = 1))), 
         arrow=arrow(length = unit(0.5, "cm"))) 
g <- g + theme_bw() + theme(legend.position="none") + xlab("longitude") + 
    ylab("latitude") + geom_text(aes(x = jitter(x), y = jitter(y))) 
g 
+0

빠른 답장을 보내 주셔서 감사합니다 :) – Saara