2014-06-17 1 views
1

"날짜", "시간", "경도", "경도", "반지름"열이있는 장치 위치의 .csv 파일이 있습니다. , "position_method" Google지도에서 점 데이터를 플롯하고 시간별 점 변화를 반영하는 애니메이션을 만들고 싶습니다.R 언어 ggmap 및 애니메이션 패키지로 플롯 된 여러 이미지에 대한 애니메이션 맵을 만드는 방법

강력한 애니메이션 패키지 (http://cran.r-project.org/web/packages/animation/animation.pdf.)와 데모 (http://xccds1977.blogspot.fi/2012/06/ggmap.html)를 사용했습니다. 루프 for(i in time) print(plotfunc(i)으로

all <- read.csv("C:/probes/2014-04-07.csv",header=T) 

#convert the time format to standard hour-min-sec format 
th < -strptime(all$time,"%H:%M:%OS") 

#select the hour part of time 
byhour <- th$h 

#plot map by hours 
plotfunc <- function(x) { 
    df <- subset(all,byhour <= x) 

    p <- ggmap(get_googlemap (center = 'Tampere', zoom=10,maptype = 'terrain'),,extent='device')+ 
    geom_point(data = df,aes(x = lon, y = lat),colour = 'red',alpha=0.7) 
} 

#get the hours of probes 
time <- sort(unique (byhour)) 

#generate and save the animation in HTML 
saveHTML({ 
      for(i in time) print (plotfunc(i)) 
      ani.options(interval = 0.5) 

      }, 
img.name = "probes_hour_plot", title = "Visualization of probes from Pirkanmmaa changing by time in a day", 
description=c("the numbers of devices receiveing from 12am") 
) 

내가 애니메이션을 가지고 있지만 오래된 것들에 새로운 지점을 오버레이, 그래서 포인트 증가 :

코드는 다음과 같습니다. 분배의 변화를 반영하지 못했습니다. 오버레이와 누적이 아닌 매 시간마다 포인트를 보여주는 방법을 알고 있습니까? 내가 필요한 것은 단지 독립적 인 이미지를 결합한 애니메이션을 만드는 것입니다.

내가 얻은 애니메이션은 Kai Xiao의 데모에서 gif와 비슷하지만 원하는 것은 아닙니다.

+0

맞습니다. 이제 작동합니다! 고마워요 & mua ~ – chenchenmomo

+0

그 것이기 때문에 나는 대답에 대한 설명을 옮겼습니다. – MrFlick

답변

2

문제는이 x가 증가함에 따라 점점 더 많은 데이터를 선택 지금 당신이

df <- subset(all,byhour <= x) 

을하고 당신이 당신의 데이터를 플롯하기 위해 사용하는 기능은 단순히 애니메이션 프로그램이 아닙니다. 누적 하위 집합 대신 롤링 창을 더 많이 사용하려면

df <- subset(all,byhours>=x-1 & byhour<= x) 

을 사용해보십시오.

관련 문제