Show Sidebar Hide Sidebar

WebGL in Plotly and R

Now in Ploty you can implement WebGL with type = "scattergl" in place of scatter for increased speed, improved interactivity, and the ability to plot even more data!

Compare WebGL and SVG

Checkout this post for a comparison of WebGL and SVG scatter plots with 75000 data points.

WebGL with many traces

library(plotly)

# Random Walk function
randWalk <- function(n = 1000, mu = 0, std = 1){
  y <- rep(0, n)
  for(i in 2:n){
    y[i] <- y[i-1] + rnorm(1, mu, std)
  }

  return(y)
}

# Create a lot of random walks
nRand <- 10000
nPlot <- 25
p <- plot_ly(x = 1:nRand, y = randWalk(n = nRand), type = "scattergl", mode = "lines", 
             line = list(width = 3, smoothing = 0.5)) %>% 
  layout(showlegend = F)

for(i in 1:nPlot){
  p <- add_trace(p, x = 1:nRand, y = randWalk(n = nRand), type = "scattergl", mode = "lines")
}

p

Reference

see scattergl for more information.

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to our Premium or Enterprise plans.