在时间戳值上绘制(x,y)坐标

时间:2013-03-22 09:16:37

标签: r visualization

我有移动数据(x,y)坐标和相应的时间戳值,我需要在R中绘制它。gvisMotionChart()和其他googleVis产品似乎不接受时间戳值。有关R包的任何想法可用于随时间可视化此运动数据?样本数据如下:

timestamp                    x    y
Feb 17, 2013 8:33:24 PM.000  724 414
Feb 17, 2013 8:34:24 PM.000  398 769
Feb 17, 2013 8:43:27 PM.000  398 769
Feb 17, 2013 8:44:15 PM.000  637 1083

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

试试这个:

DF <- read.table(text="timestamp; x; y
Feb 17, 2013 8:33:24 PM.000; 724; 414
Feb 17, 2013 8:34:24 PM.000; 398; 769
Feb 17, 2013 8:43:27 PM.000; 398; 769
Feb 17, 2013 8:44:15 PM.000; 637; 1083",
header=TRUE,sep=";",stringsAsFactors=FALSE)

DF$timestamp <- as.numeric(strptime(DF$timestamp,
                                    "%b %d, %Y %I:%M:%S %p.000",tz="GMT"))
DF$timestamp <- DF$timestamp-min(DF$timestamp)
DF$ID <- 1


library(googleVis)
M1 <- gvisMotionChart(DF, idvar="ID", timevar="timestamp",xvar="x", yvar="y")
plot(M1)