Skip to content

Commit 378c779

Browse files
authored
Merge pull request #1015 from plotly/R-text-webGL-doc-update
Created R doc for webGL text example
2 parents 325fa45 + d008980 commit 378c779

File tree

2 files changed

+226
-0
lines changed

2 files changed

+226
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: WebGL Text and Annotations in R | Examples | Plotly
3+
name: WebGL Text and Annotations
4+
permalink: r/webgl-text-and-annotations/
5+
description: How to add WebGL text labels and annotations to plots in R.
6+
layout: base
7+
thumbnail: thumbnail/webgl-text-and-annotations.jpg
8+
language: r
9+
page_type: example_index
10+
has_thumbnail: false
11+
display_as: style_opt
12+
order: 10
13+
output:
14+
html_document:
15+
keep_md: true
16+
---
17+
18+
```{r, echo = FALSE, message=FALSE}
19+
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
20+
Sys.setenv("plotly_username"="RPlotBot")
21+
Sys.setenv("plotly_api_key"="q0lz6r5efr")
22+
```
23+
### New to Plotly?
24+
25+
Plotly's R library is free and open source!<br>
26+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
27+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
28+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
29+
30+
### Version Check
31+
32+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
33+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
34+
```{r}
35+
library(plotly)
36+
packageVersion('plotly')
37+
```
38+
39+
40+
### Heatmap with Annotations
41+
42+
```{r, results = 'hide'}
43+
library(plotly)
44+
library(random)
45+
46+
n=250
47+
t=12
48+
x = c(rep(0:(n-1), times=t))
49+
y = c(rep(0:(t-1), each=n))
50+
z = randomNumbers(n=n*t, min=1, max=10, col=n)
51+
text = c(replicate(t*n, sample(c("A","T","G","C"), 1)))
52+
53+
steps = list()
54+
for (e in c(0:(n-30))){
55+
step <- list(
56+
list(
57+
args = list('xaxis.range', c(-0.5 + e, 30.5 + e)),
58+
method = "relayout",
59+
label = e,
60+
value = e
61+
)
62+
)
63+
steps[e] <- step
64+
}
65+
66+
p <- plot_ly() %>%
67+
add_trace(
68+
type='heatmap',
69+
z = z
70+
) %>%
71+
add_trace(
72+
mode = "text",
73+
text = text,
74+
type = "scattergl",
75+
textfont = list(
76+
size = 20
77+
),
78+
x = x,
79+
y = y
80+
) %>%
81+
layout(
82+
xaxis = list(
83+
range = c(-0.5, 30.5),
84+
showline = F,
85+
zeroline = F,
86+
showgrid = F
87+
),
88+
yaxis = list(
89+
showline = F,
90+
zeroline = F,
91+
showgrid = F
92+
),
93+
sliders=list(
94+
list(
95+
active = 0,
96+
steps = steps
97+
)
98+
)
99+
)
100+
101+
# Create a shareable link to your chart
102+
# Set up API credentials: https://plot.ly/r/getting-started
103+
chart_link = api_create(p, filename="webgl-text-annotation")
104+
chart_link
105+
```
106+
107+
```{r, echo=FALSE}
108+
chart_link
109+
```
110+
111+
#Reference
112+
113+
See [https://plot.ly/r/reference/#scattergl](https://plot.ly/r/reference/#scattergl) for more information and chart attribute options!
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: WebGL Text and Annotations in R | Examples | Plotly
3+
name: WebGL Text and Annotations
4+
permalink: r/webgl-text-and-annotations/
5+
description: How to add WebGL text labels and annotations to plots in R.
6+
layout: base
7+
thumbnail: thumbnail/webgl-text-and-annotations.jpg
8+
language: r
9+
page_type: example_index
10+
has_thumbnail: false
11+
display_as: style_opt
12+
order: 10
13+
output:
14+
html_document:
15+
keep_md: true
16+
---
17+
18+
19+
### New to Plotly?
20+
21+
Plotly's R library is free and open source!<br>
22+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
23+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
24+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
25+
26+
### Version Check
27+
28+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
29+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
30+
31+
```r
32+
library(plotly)
33+
packageVersion('plotly')
34+
```
35+
36+
```
37+
## [1] '4.8.0'
38+
```
39+
40+
41+
### Heatmap with Annotations
42+
43+
44+
```r
45+
library(plotly)
46+
library(random)
47+
48+
n=250
49+
t=12
50+
x = c(rep(0:(n-1), times=t))
51+
y = c(rep(0:(t-1), each=n))
52+
z = randomNumbers(n=n*t, min=1, max=10, col=n)
53+
text = c(replicate(t*n, sample(c("A","T","G","C"), 1)))
54+
55+
steps = list()
56+
for (e in c(0:(n-30))){
57+
step <- list(
58+
list(
59+
args = list('xaxis.range', c(-0.5 + e, 30.5 + e)),
60+
method = "relayout",
61+
label = e,
62+
value = e
63+
)
64+
)
65+
steps[e] <- step
66+
}
67+
68+
p <- plot_ly() %>%
69+
add_trace(
70+
type='heatmap',
71+
z = z
72+
) %>%
73+
add_trace(
74+
mode = "text",
75+
text = text,
76+
type = "scattergl",
77+
textfont = list(
78+
size = 20
79+
),
80+
x = x,
81+
y = y
82+
) %>%
83+
layout(
84+
xaxis = list(
85+
range = c(-0.5, 30.5),
86+
showline = F,
87+
zeroline = F,
88+
showgrid = F
89+
),
90+
yaxis = list(
91+
showline = F,
92+
zeroline = F,
93+
showgrid = F
94+
),
95+
sliders=list(
96+
list(
97+
active = 0,
98+
steps = steps
99+
)
100+
)
101+
)
102+
103+
# Create a shareable link to your chart
104+
# Set up API credentials: https://plot.ly/r/getting-started
105+
chart_link = api_create(p, filename="webgl-text-annotation")
106+
chart_link
107+
```
108+
109+
<iframe src="https://plot.ly/~RPlotBot/5465.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
110+
111+
#Reference
112+
113+
See [https://plot.ly/r/reference/#scattergl](https://plot.ly/r/reference/#scattergl) for more information and chart attribute options!

0 commit comments

Comments
 (0)