LoginSignup
3
3

More than 3 years have passed since last update.

R言語でアニメーション

Last updated at Posted at 2019-06-03

研究室で得たデータの動きが見たかったからRでアニメーションを作れないかな?と思った。
できるね。

animation
ggplot2
gganimation
gifski
png
ここら辺入れておけば多分大丈夫

あとはいつも通りに
ggplot()+geom_point()+transition_reveal()またはtransition_time()

レンダリングにちょっと時間かかる。俺の扱ったデータだと十数秒くらい。

transition_time()のほうが使いやすい感じ。
で、これだと早すぎて困ったから遅くする方法を探してきた。
https://stackoverflow.com/questions/52899017/slow-down-gganimate-in-r
animateで指定すればいいんだな。
とりあえずaにアニメーションを1回入れた後にduration(再生秒数)とfps(1秒当たりのコマ数)を指定すればレンダリングしたあとにアニメーションが見れる。
30fpsとかにするとレンダリング1時間とか言われてしまうので注意。

a = ggplot(data=kohinatamiho,aes(x=Length,y=Width)) + geom_point() +  labs(title = 'Date: {frame_time}')+shadow_wake(wake_length = 0.05, alpha = FALSE) + theme_bw() + transtion_time(Time)
animate(a,duration=300,fps=2)

あとshadow_wakeのwake_lengthは全体のフレーム数に対して何%のフレームを残像として残すかを指定できる(0~1の間の値で)
とマニュアルには書いてあるから全体で27000フレームある時に0.01を指定したら270フレーム分の残像が残る‥?のかな?とりあえず値小さくすれば残像の数が減りますということだけ。

参考にした記事
https://qiita.com/YM_DSKR/items/8899faef67f393a8fca4

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3