Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions _posts/r/scientific/2018-08-03-heatmap-webgl.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: WebGL Heatmaps in R | Examples | Plotly
name: WebGL Heatmaps
permalink: r/heatmap-webgl/
description: How to make webGL based heatmaps in R with Plotly.
layout: base
thumbnail: thumbnail/heatmap-webgl.jpg
language: r
page_type: example_index
has_thumbnail: true
display_as: scientific
order: 20
output:
html_document:
keep_md: true
---

```{r, echo = FALSE, message=FALSE}
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
Sys.setenv("plotly_username"="RPlotBot")
Sys.setenv("plotly_api_key"="q0lz6r5efr")
```

### New to Plotly?

Plotly's R library is free and open source!<br>
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
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>
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!

### Version Check

Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
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.

```{r}
library(plotly)
packageVersion('plotly')
```

#### WebGL Heatmap from an Image

```{r, results = 'hide'}
library("jpeg")
library("plotly")

# Image processing
url <- "https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg"
tmpf <- tempfile()
download.file(url,tmpf,mode="wb")
data <- readJPEG(tmpf)
file.remove(tmpf) # remove the downloaded temp file

zdata = rowSums(data*255, dims = 2)

p <- plot_ly(
z = zdata,
colorscale = list(c(0,1),c("rgb(155,112,184)","rgb(128,100,64)")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably make the colors pop a little more, something like you have but colorscale = list(c(0,0.5,1),c("blue", "white", "red"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @bcdunbar I have changed them to the suggested colorscale.

type = "heatmapgl"
)

# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="heatmap-webgl")
chart_link
```

``` {r, echo=FALSE}
chart_link
```

#### Reference

See [https://plot.ly/r/reference/#heatmapgl](https://plot.ly/r/reference/#heatmapgl) for more information and options!
74 changes: 74 additions & 0 deletions _posts/r/scientific/2018-08-03-heatmap-webgl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: WebGL Heatmaps in R | Examples | Plotly
name: WebGL Heatmaps
permalink: r/heatmap-webgl/
description: How to make webGL based heatmaps in R with Plotly.
layout: base
thumbnail: thumbnail/heatmap-webgl.jpg
language: r
page_type: example_index
has_thumbnail: true
display_as: scientific
order: 20
output:
html_document:
keep_md: true
---



### New to Plotly?

Plotly's R library is free and open source!<br>
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
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>
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!

### Version Check

Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
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.


```r
library(plotly)
packageVersion('plotly')
```

```
## [1] '4.7.1'
```

#### WebGL Heatmap from an Image


```r
library("jpeg")
library("plotly")

# Image processing
url <- "https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg"
tmpf <- tempfile()
download.file(url,tmpf,mode="wb")
data <- readJPEG(tmpf)
file.remove(tmpf) # remove the downloaded temp file

zdata = rowSums(data*255, dims = 2)

p <- plot_ly(
z = zdata,
colorscale = list(c(0,1),c("rgb(155,112,184)","rgb(128,100,64)")),
type = "heatmapgl"
)

# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="heatmap-webgl")
chart_link
```

<iframe src="https://plot.ly/~RPlotBot/5461.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>

#### Reference

See [https://plot.ly/r/reference/#heatmapgl](https://plot.ly/r/reference/#heatmapgl) for more information and options!