Multicategory axis type for heatmaps in R

Hi,

I am currently trying to use multicategory axis in R. So far, I managed to use multicategory y axis on bar charts with the help of this post for the python api: Multicategory Axis Type Example?, where I have to set the axis type manually:

    library(tidyverse)
library(plotly)
x = array(
  c("BB+", "BB+", "BB+", "BB", "BB", "BB",
    16, 17, 18, 16, 17, 18),
  c(6, 2)
)
p <- plot_ly() %>% 
  add_bars(y=t(x),x=c(1,2,3,4,5,6)) %>% 
  add_bars(y=t(x),x=c(6,5,4,3,2,1)) %>% 
  layout(barmode="relative", yaxis = list(type = "multicategory"))
p

However, when I try to use the same approach for heatmaps, Rstudio freezes:

q <- plot_ly() %>% 
  add_heatmap(y=(x),x=c(1,2,3,4,5,6), z = 1) %>% 
  layout(yaxis = list(type = "multicategory"))
q

Any suggestions how I can achieve the same axis for heatmaps?

I can get a mulitcat X-axis working by declaring the x values as a matrix with two rows but RStudio fails for me if I try to do the same for the Y-axis. I think that might be a bug since I don’t have any problems making a similar graph using plotly in javascript directly.

library(plotly)
q <- plot_ly() %>% 
  add_heatmap(
    y=c(1,2,3,4,5,6),
    x=rbind(c('aa', 'aa', 'bb', 'bb', 'cc', 'cc'), c(1,2,3,4,5,6)),
    z = array(seq(1,10, length.out = 36), c(6,6)))
q

Thanks @michaelbabyn for the solution. Do you want to add it as an answer or, do you mind if I add it to my related SO question: How to generate interactive “tableau style” heatmaps in R with two factors as axis labels

I can confirm that I experience the same issue on the y-axis, I will file an issue on it.

Edit: multicategory axis don’t seem to be very stable yet. I tried to expand on your solution by moving the x-axis on top of the plot and it crashes, too:

  library(plotly)
  q <- plot_ly() %>% 
    add_heatmap(
      y=c(1,2,3,4,5,6),
      x=rbind(c('aa', 'aa', 'bb', 'bb', 'cc', 'cc'), c(1,2,3,4,5,6)),
      z = array(seq(1,10, length.out = 36), c(6,6)))
  q
  qx <- q %>% layout(xaxis=list(side = "top"))
  qx

I don’t mind at all. Feel free to add this solution there.