HTML widgets work just like R plots except they produce interactive web visualizations. A line or two of R code is all it takes to produce a D3 graphic or Leaflet map. HTML widgets can be used at the R console as well as embedded in R Markdown reports and Shiny web applications. In addition to the widgets featured below you may also want to check out the htmlwidgets gallery.
Dygraphs http://rstudio.github.io/dygraphs
library(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures") %>%
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
Plotly https://plot.ly/r/
Plotly allows you to easily translate your ggplot2 graphics to an interactive web-based version, and also provides bindings to the plotly.js graphing library.
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p <- ggplot(data = diamonds, aes(x = cut, fill = clarity)) +
geom_bar(position = "dodge")
ggplotly(p)
https://github.com/rstudio/d3heatmap
Interactive heatmaps with D3 including support for row/column highlighting and zooming.
library(d3heatmap)
d3heatmap(mtcars, scale="column", colors="Blues")
https://github.com/bwlewis/rthreejs
threejs includes a 3D scatterplot and 3D globe (you can directly manipulate the scatterplot below with the mouse).
You can also install rthreejs from github
devtools::install_github("lrodriguezlujan/rthreejs", ref = "scatter_spheres_opt")
library(threejs)
N <- 100
i <- sample(3, N, replace=TRUE)
x <- matrix(rnorm(N*3),ncol=3)
lab <- c("small", "bigger", "biggest")
scatterplot3js(x, color=rainbow(N), labels=lab[i], size=i, renderer="canvas")
N <- 20000
theta <- runif(N)*2*pi
phi <- runif(N)*2*pi
R <- 1.5
r <- 1.0
x <- (R + r*cos(theta))*cos(phi)
y <- (R + r*cos(theta))*sin(phi)
z <- r*sin(theta)
d <- 6
h <- 6
t <- 2*runif(N) - 1
w <- t^2*sqrt(1-t^2)
x1 <- d*cos(theta)*sin(phi)*w
y1 <- d*sin(theta)*sin(phi)*w
i <- order(phi)
j <- order(t)
col <- c( rainbow(length(phi))[order(i)],
rainbow(length(t),start=0, end=2/6)[order(j)])
M <- cbind(x=c(x,x1),y=c(y,y1),z=c(z,h*t))
scatterplot3js(M,size=0.25,color=col,bg="black")
http://cran.at.r-project.org/web/packages/rglwidget/index.html
rglwidget renders WebGL scenes created with the rgl package.
library(rgl)
library(rglwidget)
## The functions in the rglwidget package have been moved to rgl.
library(htmltools)
theta <- seq(0, 6*pi, len=100)
xyz <- cbind(sin(theta), cos(theta), theta)
lineid <- plot3d(xyz, type="l", alpha = 1:0,
lwd = 5, col = "blue")["data"]
browsable(tagList( rglwidget(elementId = "example", width = 500, height = 400, controllers = "player"), playwidget("example", ageControl(births = theta, ages = c(0, 0, 1), objids = lineid, alpha = c(0, 1, 0)), start = 1, stop = 6*pi, step = 0.1, rate = 6,elementId = "player") ))
http://rich-iannone.github.io/DiagrammeR/
A tool for creating diagrams and flowcharts using Graphviz and Mermaid.
library(DiagrammeR)
grViz("
digraph {
layout = twopi
node [shape = circle]
A -> {B C D}
}")
http://hrbrmstr.github.io/metricsgraphics/
MetricsGraphics enables easy creation of D3 scatterplots, line charts, and histograms.
library(metricsgraphics)
mjs_plot(mtcars, x=wt, y=mpg) %>%
mjs_point(color_accessor=carb, size_accessor=carb) %>%
mjs_labs(x="Weight of Car", y="Miles per Gallon")