Three.js and R

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 for details on three.js.

See for R examples.

This project is based on the htmlwidgets package. See for details and links to many other visualization widgets for R.

New in version 0.3.0 (June, 2017)

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 and 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 for an example.

Summary of changes

The scatterplot3js() function was substantially improved and updated.

The graphjs() function is completely new.

Known issues


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")


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

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 ( 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



Travis CI status

Try the threejs package in your browser

Any scripts or data that you put into this service are public.

threejs documentation built on Aug. 13, 2017, 9:06 a.m.