Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea33633

Browse files
committed
Added webgl example
1 parent 2a24e73 commit ea33633

File tree

4 files changed

+297
-0
lines changed

4 files changed

+297
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: WebGL vs SVG| Examples | Plotly
3+
name: WebGL vs SVG in R
4+
permalink: r/webgl-vs-svg/
5+
description: How to create plots using WebGL
6+
layout: user-guide
7+
language: r
8+
page_type: example_index
9+
has_thumbnail: true
10+
display_as: get_request
11+
output:
12+
html_document:
13+
highlight: null
14+
keep_md: yes
15+
theme: null
16+
---
17+
18+
```{r, echo = FALSE, message=FALSE}
19+
knitr::opts_chunk$set(message = FALSE, eval = F)
20+
Sys.setenv("plotly_username"="RPlotBot")
21+
Sys.setenv("plotly_api_key"="q0lz6r5efr")
22+
```
23+
24+
# Compare WebGL and SVG in R
25+
26+
### Scatterplots with 75000 random points
27+
28+
### WebGL
29+
```{r}
30+
library(plotly)
31+
32+
n <- 75000
33+
x <- rnorm(n)
34+
y <- 2*x + rnorm(n, sd = 5)
35+
36+
p <- plot_ly(x = x, y = y, type = "scattergl", mode = "markers", marker = list(line = list(width = 2)))
37+
p
38+
```
39+
40+
<iframe src="https://plot.ly/~RPlotBot/2869"width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
41+
42+
### SVG
43+
> The draw time for this plot will be slow for all clients.
44+
45+
```{r}
46+
library(plotly)
47+
48+
n <- 75000
49+
x <- rnorm(n)
50+
y <- 2*x + rnorm(n, sd = 5)
51+
52+
p <- plot_ly(x = x, y = y, type = "scatter", mode = "markers", marker = list(line = list(width = 2)))
53+
p
54+
```
55+
56+
<iframe src="https://plot.ly/~RPlotBot/2871/y-vs-x/" width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
57+
58+
# References
59+
See:
60+
- [scattergl](https://plot.ly/r/reference/#scattergl)
61+
- [scatter](https://plot.ly/r/reference/#scatter)
62+
for more information.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: WebGL vs SVG| Examples | Plotly
3+
name: WebGL vs SVG in R
4+
permalink: r/compare-webgl-svg/
5+
description: Compare WebGL and SVG in R
6+
layout: user-guide
7+
language: r
8+
page_type: example_index
9+
display_as: get_request
10+
---
11+
# Compare WebGL and SVG in R
12+
13+
### Scatterplots with 75000 random points
14+
15+
### WebGL
16+
17+
```r
18+
library(plotly)
19+
20+
n <- 75000
21+
x <- rnorm(n)
22+
y <- 2*x + rnorm(n, sd = 5)
23+
24+
p <- plot_ly(x = x, y = y, type = "scattergl", mode = "markers", marker = list(line = list(width = 2)))
25+
p
26+
```
27+
28+
<iframe src="https://plot.ly/~RPlotBot/2869"width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
29+
30+
### SVG
31+
> The draw time for this plot will be slow for all clients.
32+
33+
34+
```r
35+
library(plotly)
36+
37+
n <- 75000
38+
x <- rnorm(n)
39+
y <- 2*x + rnorm(n, sd = 5)
40+
41+
p <- plot_ly(x = x, y = y, type = "scatter", mode = "markers", marker = list(line = list(width = 2)))
42+
p
43+
```
44+
45+
<iframe src="https://plot.ly/~RPlotBot/2871/y-vs-x/" width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
46+
47+
# References
48+
See below for more information:
49+
50+
- [scattergl](https://plot.ly/r/reference/#scattergl)
51+
- [scatter](https://plot.ly/r/reference/#scatter)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: WebGL vs SVG| Examples | Plotly
3+
name: WebGL vs SVG in R
4+
permalink: r/webgl-vs-svg/
5+
description: How to create plots using WebGL
6+
layout: base
7+
language: r
8+
page_type: example_index
9+
has_thumbnail: true
10+
display_as: get_request
11+
output:
12+
html_document:
13+
highlight: null
14+
keep_md: yes
15+
theme: null
16+
---
17+
18+
```{r, echo = FALSE, message=FALSE}
19+
knitr::opts_chunk$set(message = FALSE, eval = F)
20+
Sys.setenv("plotly_username"="RPlotBot")
21+
Sys.setenv("plotly_api_key"="q0lz6r5efr")
22+
```
23+
24+
# WebGL vs SVG in R
25+
26+
Now in Ploty you can implement WebGL with `type = "scatetrgl` in place of `scatter` for increased speed, improved interactivity, and the ability to plot even more data!
27+
28+
29+
## Compare WebGL and SVG
30+
31+
Checkout this [post](https://plot.ly/r/compare-webgl-svg/) for a comparison of WebGL and SVG scatter plots with 75000 data points.
32+
33+
## WebGL with 100,000 points
34+
```{r}
35+
library(plotly)
36+
37+
n <- 100000
38+
x <- rnorm(n)
39+
y <- 2*x + rnorm(n, sd = 5)
40+
41+
p <- plot_ly(x = x, y = y, type = "scattergl", mode = "markers", marker = list(line = list(width = 2)))
42+
p
43+
```
44+
45+
<iframe src="https://plot.ly/~RPlotBot/2863" width="800px" height="600px" scrolling="no" seamless="seamless"></iframe>
46+
47+
### WebGL with 1 Million points
48+
```{r}
49+
library(plotly)
50+
51+
n <- 1000000
52+
x <- rnorm(n)
53+
y <- 2*x + rnorm(n, sd = 5)
54+
55+
p <- plot_ly(x = x, y = y, type = "scattergl", mode = "markers", marker = list(line = list(width = 2)))
56+
p
57+
```
58+
59+
<iframe src="https://plot.ly/~RPlotBot/2865/y-vs-x/" width="100%" height=700 scrolling="no" seamless="seamless"></iframe>
60+
61+
62+
### WebGL with many traces
63+
```{r}
64+
library(plotly)
65+
66+
# Random Walk function
67+
randWalk <- function(n = 1000, mu = 0, std = 1){
68+
y <- rep(0, n)
69+
for(i in 2:n){
70+
y[i] <- y[i-1] + rnorm(1, mu, std)
71+
}
72+
73+
return(y)
74+
}
75+
76+
# Create a lot of random walks
77+
nRand <- 10000
78+
nPlot <- 25
79+
p <- plot_ly(x = 1:nRand, y = randWalk(n = nRand), type = "scattergl", mode = "lines",
80+
line = list(width = 3, smoothing = 0.5)) %>%
81+
layout(showlegend = F)
82+
83+
for(i in 1:nPlot){
84+
p <- add_trace(p, x = 1:nRand, y = randWalk(n = nRand), type = "scattergl", mode = "lines")
85+
}
86+
87+
p
88+
```
89+
90+
<iframe src="https://plot.ly/~RPlotBot/2867/randwalkn-nrand-vs-1nrand/" width="100%" height=700 scrolling="no" seamless="seamless"></iframe>
91+
92+
# Reference
93+
See https://plot.ly/python/reference/#scattergl for more information
94+
95+
96+
97+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: WebGL in Plotly and R| Examples | Plotly
3+
name: WebGL in Plotly and R
4+
permalink: r/webgl-vs-svg/
5+
description: How to create plots using WebGL and Plotly
6+
layout: user-guide
7+
language: r
8+
page_type: example_index
9+
display_as: get_request
10+
---
11+
# WebGL in Plotly and R
12+
13+
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!
14+
15+
16+
### Compare WebGL and SVG
17+
18+
Checkout this [post](https://plot.ly/r/compare-webgl-svg/) for a comparison of WebGL and SVG scatter plots with 75000 data points.
19+
20+
### WebGL with 100,000 points
21+
22+
```r
23+
library(plotly)
24+
25+
n <- 100000
26+
x <- rnorm(n)
27+
y <- 2*x + rnorm(n, sd = 5)
28+
29+
p <- plot_ly(x = x, y = y, type = "scattergl", mode = "markers", marker = list(line = list(width = 2)))
30+
p
31+
```
32+
33+
<iframe src="https://plot.ly/~RPlotBot/2863" width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
34+
35+
### WebGL with 1 Million points
36+
37+
```r
38+
library(plotly)
39+
40+
n <- 1000000
41+
x <- rnorm(n)
42+
y <- 2*x + rnorm(n, sd = 5)
43+
44+
p <- plot_ly(x = x, y = y, type = "scattergl", mode = "markers", marker = list(line = list(width = 2)))
45+
p
46+
```
47+
48+
<iframe src="https://plot.ly/~RPlotBot/2865/y-vs-x/" width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
49+
50+
51+
### WebGL with many traces
52+
53+
```r
54+
library(plotly)
55+
56+
# Random Walk function
57+
randWalk <- function(n = 1000, mu = 0, std = 1){
58+
y <- rep(0, n)
59+
for(i in 2:n){
60+
y[i] <- y[i-1] + rnorm(1, mu, std)
61+
}
62+
63+
return(y)
64+
}
65+
66+
# Create a lot of random walks
67+
nRand <- 10000
68+
nPlot <- 25
69+
p <- plot_ly(x = 1:nRand, y = randWalk(n = nRand), type = "scattergl", mode = "lines",
70+
line = list(width = 3, smoothing = 0.5)) %>%
71+
layout(showlegend = F)
72+
73+
for(i in 1:nPlot){
74+
p <- add_trace(p, x = 1:nRand, y = randWalk(n = nRand), type = "scattergl", mode = "lines")
75+
}
76+
77+
p
78+
```
79+
80+
<iframe src="https://plot.ly/~RPlotBot/2867/randwalkn-nrand-vs-1nrand/"width="900px" height="600px" scrolling="no" seamless="seamless"></iframe>
81+
82+
# Reference
83+
see [scattergl](https://plot.ly/r/reference/#scattergl) for more information.
84+
85+
86+
87+

0 commit comments

Comments
 (0)