Skip to content

Commit ac4e635

Browse files
authored
Merge pull request #998 from plotly/R-heatmap-webgl-doc-update
Created WebGL heatmap doc for R API
2 parents 900d739 + 4e5a2b5 commit ac4e635

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: WebGL Heatmaps in R | Examples | Plotly
3+
name: WebGL Heatmaps
4+
permalink: r/heatmap-webgl/
5+
description: How to make webGL based heatmaps in R with Plotly.
6+
layout: base
7+
thumbnail: thumbnail/heatmap-webgl.jpg
8+
language: r
9+
page_type: example_index
10+
has_thumbnail: true
11+
display_as: scientific
12+
order: 20
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+
24+
### New to Plotly?
25+
26+
Plotly's R library is free and open source!<br>
27+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
28+
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>
29+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
30+
31+
### Version Check
32+
33+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
34+
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.
35+
36+
```{r}
37+
library(plotly)
38+
packageVersion('plotly')
39+
```
40+
41+
#### WebGL Heatmap from an Image
42+
43+
```{r, results = 'hide'}
44+
library("jpeg")
45+
library("plotly")
46+
47+
# Image processing
48+
url <- "https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg"
49+
tmpf <- tempfile()
50+
download.file(url,tmpf,mode="wb")
51+
data <- readJPEG(tmpf)
52+
file.remove(tmpf) # remove the downloaded temp file
53+
54+
zdata = rowSums(data*255, dims = 2)
55+
56+
p <- plot_ly(
57+
z = zdata,
58+
colorscale = list(c(0,0.5,1),c("blue", "white", "red")),
59+
type = "heatmapgl"
60+
)
61+
62+
# Create a shareable link to your chart
63+
# Set up API credentials: https://plot.ly/r/getting-started
64+
chart_link = api_create(p, filename="heatmap-webgl")
65+
chart_link
66+
```
67+
68+
``` {r, echo=FALSE}
69+
chart_link
70+
```
71+
72+
#### Reference
73+
74+
See [https://plot.ly/r/reference/#heatmapgl](https://plot.ly/r/reference/#heatmapgl) for more information and options!
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: WebGL Heatmaps in R | Examples | Plotly
3+
name: WebGL Heatmaps
4+
permalink: r/heatmap-webgl/
5+
description: How to make webGL based heatmaps in R with Plotly.
6+
layout: base
7+
thumbnail: thumbnail/heatmap-webgl.jpg
8+
language: r
9+
page_type: example_index
10+
has_thumbnail: true
11+
display_as: scientific
12+
order: 20
13+
output:
14+
html_document:
15+
keep_md: true
16+
---
17+
18+
19+
20+
### New to Plotly?
21+
22+
Plotly's R library is free and open source!<br>
23+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
24+
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>
25+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
26+
27+
### Version Check
28+
29+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
30+
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.
31+
32+
33+
```r
34+
library(plotly)
35+
packageVersion('plotly')
36+
```
37+
38+
```
39+
## [1] '4.7.1'
40+
```
41+
42+
#### WebGL Heatmap from an Image
43+
44+
45+
```r
46+
library("jpeg")
47+
library("plotly")
48+
49+
# Image processing
50+
url <- "https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg"
51+
tmpf <- tempfile()
52+
download.file(url,tmpf,mode="wb")
53+
data <- readJPEG(tmpf)
54+
file.remove(tmpf) # remove the downloaded temp file
55+
56+
zdata = rowSums(data*255, dims = 2)
57+
58+
p <- plot_ly(
59+
z = zdata,
60+
colorscale = list(c(0,0.5,1),c("blue", "white", "red")),
61+
type = "heatmapgl"
62+
)
63+
64+
# Create a shareable link to your chart
65+
# Set up API credentials: https://plot.ly/r/getting-started
66+
chart_link = api_create(p, filename="heatmap-webgl")
67+
chart_link
68+
```
69+
70+
<iframe src="https://plot.ly/~RPlotBot/5461.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
71+
72+
#### Reference
73+
74+
See [https://plot.ly/r/reference/#heatmapgl](https://plot.ly/r/reference/#heatmapgl) for more information and options!

0 commit comments

Comments
 (0)