recharts4rd3heatmap

Zoom like in d3heatmap


Is there a way to zoom heatmaps in echarts4r similar to d3heatmap? (https://github.com/rstudio/d3heatmap). The purpose is to use the callbacks in echarts4r to trigger events when clicking and hovering over on the heatmap which d3heatmap doesn't have (that I know of).

This code is copied from (https://echarts4r.john-coene.com/articles/chart_types.html#heatmap) with the addition of the brush. The brush shows and can select a zoom window, however the chart doesn't zoom.

v <- LETTERS[1:10]
matrix <- data.frame(
  x = sample(v, 300, replace = TRUE), 
  y = sample(v, 300, replace = TRUE), 
  z = rnorm(300, 10, 1),
  stringsAsFactors = FALSE
) %>% 
  dplyr::group_by(x, y) %>% 
  dplyr::summarise(z = sum(z)) %>% 
  dplyr::ungroup()

matrix %>% 
  e_charts(x) %>% 
  e_heatmap(y, z) %>% 
  e_visual_map(z) %>% 
  e_title("Heatmap") %>%
  e_brush() # add the brush

Solution

  • The brush and the zoom are two different things in echarts: use e_datazoom instead.

    v <- LETTERS[1:10]
    matrix <- data.frame(
      x = sample(v, 300, replace = TRUE), 
      y = sample(v, 300, replace = TRUE), 
      z = rnorm(300, 10, 1),
      stringsAsFactors = FALSE
    ) %>% 
      dplyr::group_by(x, y) %>% 
      dplyr::summarise(z = sum(z)) %>% 
      dplyr::ungroup()
    
    matrix %>% 
      e_charts(x) %>% 
      e_heatmap(y, z) %>% 
      e_visual_map(z) %>% 
      e_title("Heatmap") %>%
      e_datazoom() # use zoom