gridSVG
パッケージを使用してアニメーション化されたSVGプロットを作成する方法を学び始めています。テストとして、開始位置から終了位置に移動して、一連のポイントをアニメートしたいと思います。この例は、パッケージの最初のビネットの例に大まかに基づいています。
まず、いくつかのデータ:
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")
を使用して、独自のgrobに各ポイントを描画することで、これを回避でき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")
単一のグロブ内の複数のポイントをアニメーション化できますか、それともループなしでポイントをアニメーション化できますか?