|
| 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! |
0 commit comments