I have a .csv file of devices positions with columns "Date","time","lat","lon","radius", "position_method". I want to plot the points data on Google map and make animation to reflect points changes by hour.
I used the powerful animation package ( http://cran.r-project.org/web/packages/animation/animation.pdf . ) and a demo ( http://xccds1977.blogspot.fi/2012/06/ggmap.html ).
The codes are as following:
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")
)
By the loop for( i in time) print(plotfunc(i)
I got an animation but it overlay new points on old ones, so the points are increasing. It could not reflect the changes of distribution. Do you know how to make the animation just show the points in each hour one by one rather than any overlay and accumulation? Only what I need is just making animation combining independent images.
The animation I got is like the gif in the demo from Kai Xiao, but it is not what I wish.
The problem isn't the animation program, it's simply the function you are using to plot your data, right now you are doing
df <- subset(all,byhour <= x)
which selects more and more data as x
increases. Try
df <- subset(all,byhours>=x-1 & byhour<= x)
instead to use more of a rolling window rather than a cumulative subset.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.