【R】ggrgl
2020年12月3日
1. はじめに
ggrglは、ggplotを3次元に拡張するパッケージです。ggplotにz軸が追加され、devoutrglによってOpenGLでレンダリングされるため、インタラクティブなプロットができます。
2. インストール
Githubからインストールします。
# install.package('remotes')
remotes::install_github('coolbutuseless/devout')
remotes::install_github('coolbutuseless/devoutrgl')
remotes::install_github('coolbutuseless/triangular')
remotes::install_github('coolbutuseless/snowcrash')
remotes::install_github('coolbutuseless/cryogenic')
remotes::install_github('coolbutuseless/ggrgl', ref='main')
3. 使ってみる
library(ggplot2)
library(rgl)
library(ggrgl)
p <- ggplot(mtcars) +
geom_density_z(aes(mpg, fill=as.factor(cyl), z = cyl), colour = '#ffffff00',
extrude = TRUE) +
scale_fill_brewer(palette = 'Set1') +
theme_ggrgl() +
labs(
title = "ggrgl::geom_density_z()",
subtitle = "with {devoutrgl}"
)
devoutrgl::rgldev(fov = 30, view_angle = -30)
p
invisible(dev.off())

4. さいごに
z軸(奥行)があると、さらに表現力が増しますね。様々なプロットに使えるようですので、これからどんどん使ってみます。