ABSTRACT

The plotly package provides two functions for displaying rectangular bins: add_heatmap() and add_histogram2d(). For numeric data, the add_heatmap() function is a 2D analog of add_bars() (bins must be pre-computed), and the add_histogram2d() function is a 2D analog of add_histogram() (bins can be computed in the browser). Thus, I recommend add_histogram2d() for exploratory purposes, since you don’t have to think about how to perform binning. It also provides a useful zs- mooth 1 attribute for effectively increasing the number of bins (currently, “best” performs a bi-linear interpolation 2 , a type of nearest neighbors algorithm), and nbinsx 3 /nbinsy 4 attributes to set the number of bins in the x and/or y directions. Figure 7.1 compares three different uses of add_histogram() : (1) plotly.js’s default binning algorithm, (2) the default plus smoothing, (3) setting the number of bins in the x and y directions. It is also worth noting that filled contours, instead of bins, can be used in any of these cases by using add_histogram2dcontour() instead of add_histogram2d(). Three different uses of <monospace>histogram2d()</monospace>. https://s3-euw1-ap-pe-df-pch-content-public-p.s3.eu-west-1.amazonaws.com/9780429447273/5aa76a70-2d8a-4f48-af74-4a299517eb99/content/fig7_1.tif" xmlns:xlink="https://www.w3.org/1999/xlink"/> p <- plot_ly(diamonds, x = ~log(carat), y = ~log(price)) subplot(  add_histogram2d(p) %>%   colorbar(title = "default") %>%   layout(xaxis = list(title = "default")),  add_histogram2d(p, zsmooth = "best") %>%   colorbar(title = "zsmooth") %>%   layout(xaxis = list(title = "zsmooth")),  add_histogram2d(p, nbinsx = 60, nbinsy = 60) %>%   colorbar(title = "nbins") %>%   layout(xaxis = list(title = "nbins")),  shareY = TRUE, titleX = TRUE )