Three.js widgets for R and shiny. The package includes
The widgets are easy to use and render directly in RStudio, in R markdown, in Shiny applications, and from command-line R via a web browser. They produce high-quality interactive visualizations with just a few lines of R code.
Visualizations optionally use accelerated WebGL graphics, falling back to non-accelerated graphics for systems without WebGL when possible.
See https://threejs.org for details on three.js.
See https://bwlewis.github.io/rthreejs for R examples.
This project is based on the htmlwidgets package. See http://htmlwidgets.org for details and links to many other visualization widgets for R.
The new 0.3.0 package version introduces major changes. The scatterplot3js()
function generally works as before but with more capabilities. The graphjs()
function is very different with a new API more closely tied to the igraph
package.
The threejs package now depends on igraph. If you're doing serious network analysis, you're probably already using igraph (or you should be). Threejs now uses external graph layouts (either from igraph or elsewhere). This gives much greater graph layout flexibility, something I was looking for, but also removes the cute (but slow and crude) force-directed JavaScript animation previously used. To partially make up for that, several new graph animation and interaction schemes are newly available.
See https://bwlewis.github.io/rthreejs/animation/animation.html and https://bwlewis.github.io/rthreejs/advanced/advanced.html for short tutorials on the new graph animation capabilities.
Performance of graphjs()
is generally much improved using extensive buffering
and custom WebGL shaders where needed. See
https://bwlewis.github.io/rthreejs/ego/index.html for an example.
The scatterplot3js()
function was substantially improved and updated.
pch
option supports many point styles with size control.points3d()
interface has changed to support pipelining.lines3d()
.demo("crosstalk", package="threejs")
).use.orbitcontrols=TRUE
option for more CPU-efficient (but less fluid) rendering (good for laptops), also applies to graphjs()
.The graphjs()
function is completely new.
demo(package="threejs")
for examples.brush=TRUE
option.Use the devtools package to install threejs directly from GitHub on any R platform (Mac, Windows, Linux, ...). You'll need the 'devtools' package.
if(!require("devtools")) install.packages("devtools")
devtools::install_github("bwlewis/rthreejs")
See ?scatterplot3d
for more examples and detailed help.
z <- seq(-10, 10, 0.1)
x <- cos(z)
y <- sin(z)
scatterplot3js(x, y, z, color=rainbow(length(z)))
The following example plots an undirected graph with 4039 vertices and 88234 edges from the Stanford SNAP network repository http://snap.stanford.edu/data/facebook_combined.txt.gz.
data(ego)
graphjs(ego, bg="black")
The next example illustrates the globe widget by plotting the relative population of some cities using data from the R maps package on a globe. It's based on the JavaScript WebGL Globe Toolkit (https://github.com/dataarts) by the Google Creative Lab Data Arts Team.
runApp(system.file("examples/globe", package="threejs"))
For detailed help on the widgets and additional examples, see
?scatterplot3js
?globejs
?graphjs
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.