【发布时间】:2020-09-27 23:31:58
【问题描述】:
我想为状态之间的填充值转换设置动画。我有一个 100x100 的 geom_points 网格,其值介于 0 和 1 之间。本质上,这些点在每个时间点都保持在相同的位置,但它们的填充值会发生变化,我想对其进行动画处理。这里是数据的摘录
head(strg)
Var1 Var2 const4 pred id
1 -1.0000000 -1 1 3.337224e-37 1
2 -0.9292929 -1 1 1.922538e-34 2
3 -0.8585859 -1 1 2.561529e-32 3
4 -0.7878788 -1 1 2.522569e-30 4
5 -0.7171717 -1 1 1.433660e-28 5
6 -0.6464646 -1 1 1.795601e-27 6
其中 const4 呈现不同的状态。这里是初始情节
ggplot(strg, aes(x = strg[,1], y = strg[,2])) + geom_point(aes(color = strg[,"pred"])) + scale_color_gradient("Predictions", low = "blue", high = "orange")
我现在的问题是
- 如何构建构建 ggplot 的数据框?我想过让 const4 中的所有状态都重复它。
- 在 gganimate 中使用什么函数来可视化过渡?
【问题讨论】:
-
您能否提供可重现的数据样本?
-
我的错 @Robin Turkington
steps <- seq(-1, 6) num.interpolating.points <- 100 x.values <- seq(-1, 6, len = num.interpolating.points) y.values <- seq(-1, 6, len = num.interpolating.points) test.points <- data.frame(expand.grid(x.values, y.values)) test.points$pred <- runif(dim(test.points)[2]) strg <- do.call(rbind, replicate(length(steps), test.points, simplify=FALSE)) strg <- as.data.frame(strg)其中 steps 是我想要动画的状态数 -
谢谢,我现在就想办法。