Monthly Archives: October 2014

Interactive Highcharts Heat Maps in R with rCharts

highcharts-heatmap

This post shows how to create Highchart Heat Maps in R using the rCharts package. Heat maps are newer Highcharts extensions. Getting rCharts to display heat maps is a little more involved, since the current version of rCharts 0.4.5 does not ship these extensions. Showing heat maps in R with rCharts requires direct linking of these additional JavaScript files.

I will show both how to create a standalone HTML page and a Shiny app. We use the example from http://www.highcharts.com/demo/heatmap to create a map for the sales per employee data.

Here is the code in order to create a standalone HTML page containing a Highcharts Heat Map:

rCharts 0.4.5. currently does include only the standard Highcharts JavaScript files and no extensions for Heat Maps or Highstocks like modules/heatmap.js or stocks/highstock.js. So I include these additional files using the p$addAssets() method.

Still, one need to include more than just the heatmap.js to get it work. The problem seems to be that simply adding the heatmap.js is not enough, there seems to be a version conflict with the HighCharts JavaScript files in rCharts. Therefore, I load some more Highcharts and jQuery JS files externally in order not to run into some NullPointerExceptions when creating the Heatmap.

In Shiny Apps, one can load the JS in the tag$head() function of ui.R instead of the p$addAssets() method:

The Shiny app is available at http://stefanwilhelm.shinyapps.io/heatmap/. The source code of the Shiny example can be found on GitHub at https://github.com/stefanwilhelm/heatmap.

I have asked Ramnath Vaidyanathan, the author of rCharts, to include Highcharts extensions like modules/heatmap.js directly into the package to make them easier to use in R. I will update this post once this change is implemented in rCharts. Until then, you might find my proposed workarounds useful for creating Highcharts Heat Maps.

Edit Apr 19, 2015:
When your data set is larger than 1000 data points, you need to increase the Highcharts turboThreshold parameter as follows

For this Highcharts limitation to 1000 data points by default, see the Highcharts documentation or StackOverflow questions like highcharts-3-cannot-render-more-than-1000-points-in-one-series.
Thanks to Bing Zhang for a question that led me to this issue.

Articles

Publications

Working Papers

R packages

tmvtnorm

This package contains useful methods for the truncated multivariate normal distribution. An overview article has been published in The R Journal as “tmvtnorm: A Package For the Truncated Multivariate Normal Distribution” (joint with Manjunath B G). More information about this package is available at CRAN http://cran.r-project.org/tmvtnorm

fCertificates

fCertificates contains a collection for pricing methods for structured derivatives in Germany and Switzerland. It covers simple structures like covered calls, or so-called Easy-Express certificates. All these certificates have in common that they may be duplicated using simpler plain-vanilla call and put options or barrier options (e.g. down-and-out put). More information is available at the package website at http://CRAN.R-project.org/package=fCertificates.

fExpressCertificates

This package implements a number of methods for pricing autocallables, which are primarily marketed under the name of Express Certificates in Germany. It prices these derivatives in a framework of truncated multinormal returns and, hence, builds upon the tmvtnorm package. More information is available at the package website at http://CRAN.R-project.org/package=fExpressCertificates.

spatialprobit

This package implements the Bayesian estimation of spatial limited-dependent variable models in R like spatial lag and error probit, spatial ordered probit and spatial Tobit. The estimation has been optimized for large data sets with the help of sparse spatial weights matrices.

More information, including code examples, is available at CRAN http://CRAN.R-project.org/package=spatialprobit and in our R Journal article “Estimating Spatial Probit Models in R” (joint with Miguel Godinho de Matos).