Add custom annotations to heatmap in plotly

Hello all,

I am trying to add annotations to a heatmap by using the add_annotations function in plotly R but am unable to control placement of text in the heatmap. For instance, in the plot below, I am tryng to annotate x=S1, y=S1, but the text ends up in the middle of the plot. Changing ax and ay does not seem to help.

random_matrix <- matrix(runif(n=100, min=1, max=20), nrow=10)
colnames(random_matrix) <- c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9","S10")
fig <- plot_ly(z = random_matrix, x=colnames(random_matrix), y=colnames(random_matrix), type = "heatmap")

fig <- fig %>% add_annotations(x = random_matrix[1,1],
                               y = random_matrix[1,1],
                               text = "KM267916",
                               xref = "x",
                               yref = "y",
                               showarrow = FALSE,
                               ax = 0,
                               ay = 0
)
fig

Any help is much appreciated!

Thanks

The x and y axis is based on colnames(random_matrix) not on random_matrix.

Please check the following:

library(plotly)

random_matrix <- matrix(runif(n=100, min=1, max=20), nrow=10)
colnames(random_matrix) <- c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9","S10")
fig <- plot_ly(z = random_matrix, x=colnames(random_matrix), y=colnames(random_matrix), type = "heatmap")

fig <- fig %>% add_annotations(x = colnames(random_matrix)[1],
                               y = colnames(random_matrix)[1],
                               text = "KM267916",
                               xref = "x",
                               yref = "y",
                               showarrow = FALSE,
                               ax = 0,
                               ay = 0
)
fig