LoginSignup
6
5

More than 5 years have passed since last update.

plotly: ggplotをanimationする

Last updated at Posted at 2016-11-17

ggplotを使ったアニメーションがplotlyで紹介されていました。

こちらの記事をみて、animationするplotをかけるようなので、書いてみました。開発中みたいなので、今後内容は代わるかもしれません。

先に、devtoolsやplotlyのinstallが必要なのでお済みでない方は、

https://cpsievert.github.io/plotly_book/installation.html

こちらをみてinstallしておいてください

plotly_animation
#けっこう時間がかかる
devtools::install_github("ropensci/plotly#554") 
install.packages("gapminder")

#libraryとデータの読み込み
library(plotly)
data(gapminder, package = "gapminder")

#作図オブジェクト作成
gg <- ggplot(gapminder, aes(gdpPercap, lifeExp)) +
  geom_point(aes(size = pop, color = continent, frame = year, ids = country)) +
  scale_x_log10()

#警告:  Ignoring unknown aesthetics: frame, ids
#☝️warningがでてるよお兄さん

#作図
ggplotly(gg)

Unknown.png

スクリーンショットで恐縮ですがちゃんと動きました!! presentationに使えそうですね、自分の時系列データを動かしてみたいです。

6
5
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
6
5