LoginSignup
0
1

More than 1 year has passed since last update.

R 3dplot3通り

Posted at

※備忘録

使用データセット
image.png

①RGLパッケージで静的な3次元プロットを得る。

data(trees)
library("rgl")
plot3d(trees)

image.png

一応マウスドラッグで回転可能。出力もplot3dの構文かRGLパッケージの関数を使えばできそう(やらないけど)。

image.png

②RGLパッケージでWebGLで動くHTMLファイルを保存できるらしい。

# webgl形式?で出力してくれるはずなのだが、手元のchromeだとjs有効にしても表示されない
data(trees)
library("rgl")
plot3d(trees)
writeWebGL(width=500, height=550)

上記手順で出力したいWebGLフォルダの中に目的のファイルを出力できる。
あとはブラウザで表示するだけなのだが、

image.png

以下のようになぜかjs有効でも見ることができない。今回はメモなのでこの辺は深く立ち入らない。

image.png

③アニメーションライブラリを使用してアニメーション形式で出力
ここも深く立ち入らないが、以下の構文でアニメーションファイルを出力できる。
ggplot2の拡張機能にも類似の機能があるらしいので、後々調べる。

install.packages("animation")
library("animation")
library("scatterplot3d")
# ani.start()
animation::saveHTML(expr=for(i in 0:35) {
                        scatterplot3d(trees, angle = i*10+5)
                      })

上記実行でhtmlファイルを得られるので興味がある方は実行してみてください。

0
1
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
0
1