r - R中带有时间戳的实时自动递增ggplot
问题描述
继续这个线程:
library(animation)
library(ggplot2)
# your data
n <- 200
df <- data.frame(time=1:n,y=runif(n))
window <- 100
# create the animation
saveHTML({
for(i in 1:(n-window)) {
print(ggplot(df) + geom_line(aes(x=time, y=y), size=0.7) + xlim(i,i+window))
}
})
以上作品精美
当我生成带有日期和时间的时间戳时。它不再起作用了。该图是静态的,而不是在 x 轴上沿时间移动。
timestamp <- seq(ISOdate(2016, 12, 01), ISOdate(2016, 12, 31), "hour")
df2 <- data.frame(timestamp, y = runif(length(timestamp)))
window <- 100
# create the animation
saveHTML({
for (i in 1:(length(timestamp)-window)) {
print(ggplot(df2) +
geom_line(aes(timestamp, y), size = 0.20) +
ggtitle("Real-time ggplot") +
xlab("time") +
ylab("count"))
}
})
解决方案
推荐阅读
- html - 我想要更新表单中的预选选项
- unity3d - 如何禁用瓷砖地图上单个瓷砖的碰撞器?
- kubernetes - minikube 中的 TCP 和 UDP 路由,不使用 hostNetwork
- mysql - 使用 INNER 连接的 SQL 查询耗时太长
- visual-studio-code - VSCode Python 智能感知
- android - 是否可以将按钮放置为 layout_above="view1 && view2"?
- node.js - 如何在不使用 Auth0 通用登录的情况下配置 auth0 身份验证/授权?
- python - 使用 Django 测试获取 live_server 夹具
- javascript - 当 stacknavigator 与 DrawerNavigator 嵌套时,标题标题不起作用
- python - 根据值更新熊猫浮点数会产生意外结果