gridSVG
パッケージを使ってアニメーションSVGプロットを作成する方法を学び始めました。テストとして、最初の位置から最後の位置に移動してポイントのセットをアニメーション化したい。この例は、パッケージのfirst vignetteのものに基づいています。gridSVGでベクター化された方法でポイントをアニメーション化する方法は?
まず、いくつかのデータ:
n_points <- 20
start <- data.frame(
x = runif(n_points),
y = runif(n_points)
)
end <- data.frame(
x = runif(n_points),
y = runif(n_points)
)
基本的な考え方は、「SVGに保存し、新しいページを描く最初のフレームの内容を追加し、アニメーション化」しているようです。私の最初の試みは、すべてのポイントを同じ場所に描きます。 grid.animate
に各ポイントを個別に移動する必要があると伝える方法がわかりません。
grid.newpage()
with(start,
grid.points(x, y, default.units = "npc", name = "points")
)
grid.animate(
"points",
x = c(start$x, end$x),
y = c(start$y, end$y)
)
gridToSVG("point_test1.svg")
私はlapply
を使用して、独自のグロブで各点を描画することで、このラウンドを取得することができます。これはうまくいくが、汚れている感じがある–そこにベクター化されたやり方があります。
grid.newpage()
lapply(seq_len(n_points), function(i)
{
gname = paste("points", i, sep = ".")
with(start,
grid.points(x[i], y[i], default.units = "npc", name = gname)
)
grid.animate(
gname,
x = c(start$x[i], end$x[i]),
y = c(start$y[i], end$y[i])
)
})
gridToSVG("point_test2.svg")
私もanimUnit
を使用してみましたが、私はid
パラメータを指定する方法を見つけ出すことはできません。
grid.newpage()
with(start,
grid.points(x, y, default.units = "npc", name = "points")
)
x_points <- animUnit(
unit(c(start$x, end$x), "npc"),
timeid = rep(1:2, each = n_points),
id = rep(1:2, n_points)
)
y_points <- animUnit(
unit(c(start$y, end$y), "npc"),
timeid = rep(1:2, each = n_points),
id = rep(1:2, n_points)
)
grid.animate( #throws an error: Expecting only one value per time point
"points",
x = x_points,
y = y_points
)
gridToSVG("point_test3.svg")
は、私は、単一のグロブ内の複数のポイントをアニメーション化、あるいはループせずにポイントをアニメーション化することはできますか?
ああ、私はそれが単純でなければならないことを知っていました。ありがとう。 –