iheatmapr
iheatmapr copied to clipboard
Adding custom text via layout option fails
I'm attempting to overlay text over the heatmap itself to give additional information (e.g something like this:

I believe there's no built-in functionality to do so, so I was trying to use the layout option to add the text via plotly. As a minimum reproducible example, here is a very basic plot:
data <- matrix(c(1, 2, 3, 4), nrow = 2)
plot <- iheatmap(data = data, layout = list(annotations = list(text = "hi", x = 0.5, y = 0.5, xref = "x", yref = "y")))
The heatmap I get looks like this:

This looks exactly the same as the same plot with no annotations:
plot <- iheatmap(data = data)

I have very little experience with plotly, so this may be on me, but any help would be appreciated! If there is a simpler way to overlay text, please also let me know.
You would need to pass the annotations as a list of list, e.g.
plot <- iheatmap(data = data, layout = list(annotations = list(list(text = "hi", x = 0.5, y = 0.5, xref = "x", yref = "y"))))
Note that this kind of annotation will add a little arrow, which may not be what you want here... but can be addressed by adding showarrow = FALSE
I think adding an option to make it easy to add overlay text would be a nice addition to this package, so I'll leave this issue open...
Thank you, greatly appreciate the help!
Sorry to bug you again, but I have discovered a new issue related to this.
Under your suggestion, the annotation works well:
iheatmap(data = data, layout = list(annotations = list(list(text = "hi", x = 1, y = 1, xref = "x", yref = "y", showarrow = F)))) produces:
(please ignore the bar across the top, RStudio seemed to be glitching on image export)
However, when I try to do the same thing and add row labels, the annotation disappears:
iheatmap(data = data, layout = list(annotations = list(list(text = "hi", x = 1, y = 1, xref = "x", yref = "y", showarrow = F)))) %>% add_row_labels(ticktext = c("a", "b")) produces:

I was thinking that the row labels might be "overriding" the annotations, so I tried to add them on afterwards via "modify_layout", but the problem persisted.
iheatmap(data = data) %>% add_row_labels(ticktext = c("a", "b")) %>% modify_layout(list(annotations = list(list(text = "hi", x = 1, y = 1, xref = "x", yref = "y", showarrow = F)))) produced:

I assume this is actually a bug, or perhaps I'm simply extending the package beyond its intended use.
I would like to follow up on this issue.