ggplot2 动画显示了一些空图

ggplot2 animation shows some empty plots

我试图在动画中绘制很多散点图,但很多散点图只显示一个空图。每次我 运行 code/adjust 范围时它也不同。 有些情节确实有效,它们都应该看起来像这样:

但是大部分的剧情是这样的:

这是我的代码:

library(ggplot2)
library(animation)

begintime <- min(dfL$time)
endtime <- max(dfL$time)
beginRange <- begintime
endRange <- begintime + 10

dateRangeBetween <- function(x,y){dfL[dfL$time >= x & dfL$time <= y,]}

saveHTML({
  for (i in 1:20) {
    dfSub <- dateRangeBetween(beginRange, endRange)
    ggScatterplot = ggplot(data = dfSub, aes(x = UTM_WGS84.Longitude, y = UTM_WGS84.Latitude)) + ggtitle("Coordinates") + xlab("Longitude") + ylab("Latitude") + theme(legend.position = "top") + geom_point()

    beginRange <- beginRange + 10
    endRange <- endRange + 10
    print(ggScatterplot)
  }
}, img.name = "coordinatesplots", imgdir = "coordinatesplots", htmlfile = "coordinatesplots.html", 
outdir = getwd(), autobrowse = FALSE, ani.height = 400, ani.width = 600, 
verbose = FALSE, autoplay = TRUE, title = "Coordinates")

这是我的数据框示例:

    track                    time UTM_WGS84.Longitude UTM_WGS84.Latitude
1       1 2015-10-14 23:59:55.711            5.481687           51.43635
2       1 2015-10-14 23:59:55.717            5.481689           51.43635
3       1 2015-10-14 23:59:55.723            5.481689           51.43635
4       1 2015-10-14 23:59:55.730            5.481690           51.43635
5       1 2015-10-14 23:59:55.763            5.481691           51.43635

有人可以帮我解决这个问题吗?

您的地块为空的最可能原因是您的 data.frame 的子集本身为空。

我认为(如果没有看到您的完整数据很难说)您的问题是您没有按正确的时间量递增。默认情况下,向日期添加数字会添加秒数。我怀疑您的整个数据范围不到 10 秒,因此只有第一个图会显示一些数据。之后时间范围将超出您的数据范围。

如果是这种情况,只需将 + 10 更改为您要添加的实际时间。 1:1秒,0.1:十分之一秒,等等...