block by timelyportfolio 1be37f57ecb153917f5e

Heatmap of touches (in rbokeh)

@jalapic did these really nice set of touch heatmap charts. On Twitter, there was a discussion how to do this interactively with d3.js or some other JavaScript. I definitely have some ideas how to accomplish this, but for now let’s see how we can kind of do it in rbokeh. There is just a small issue with palette selection in Bokeh that does not let us allow a no color that prevents us from getting really close.

## https://gist.github.com/jalapic/3616c0197ece24060e99
library(rbokeh)
library(dplyr)

gana <- read.csv("https://gist.githubusercontent.com/jalapic/3616c0197ece24060e99/raw/2bc2361c5fceb9be80dece9b7ffa14d129a3edfb/gana.csv")

figure() %>%
  ly_image(
    ggb$data[[1]][,c("x","y","density")] %>%
      mutate( z = round( density * 1e6 ) ) %>%
      select( x, y, z ) %>%
      spread( x, z ) %>%
      as.matrix
    ,
  )

grDevices:::.smoothScatterCalcDensity(gana,nbin=200) %>>%
  (ss~
     ly_image(
       figure( width = 694, height = 460, xlim = c(0,100), ylim = c(0,100) )
       ,ss$fhat
       ,y = min(ss$x1)
       ,x = min(ss$x2)
       ,dh = max(ss$x1) - min(ss$x1)
       ,dw = max(ss$x2) - min(ss$x2)
     )
  ) %>>%
  ly_rect( xleft = 0, xright = 100, ybottom = 0, ytop = 100, line_color = "#000000", fill_alpha = 0 ) %>>%
  ly_rect( xleft = 0, xright = 50, ybottom = 0, ytop = 100, line_color = "#000000", fill_alpha = 0 ) %>>%
  ly_rect( xleft = 17, xright = 0, ybottom = 21, ytop = 79, line_color = "#000000", fill_alpha = 0 ) %>>%
  ly_rect( xleft = 83, xright = 100, ybottom = 21, ytop = 79, line_color = "#000000", fill_alpha = 0 ) %>>%
  ly_rect( xleft = 0, xright = 6, ybottom = 36.8, ytop = 63.2, line_color = "#000000", fill_alpha = 0 ) %>>%
  ly_rect( xleft = 100, xright = 94, ybottom = 36.8, ytop = 63.2, line_color = "#000000", fill_alpha = 0 )

gana.csv