ropensci / iheatmapr

Complex, interactive heatmaps in R
https://docs.ropensci.org/iheatmapr
Other
267 stars 35 forks source link

Adding custom text via layout option fails #47

Open romert01 opened 5 years ago

romert01 commented 5 years ago

I'm attempting to overlay text over the heatmap itself to give additional information (e.g something like this: image

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: image

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

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.

AliciaSchep commented 4 years ago

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

AliciaSchep commented 4 years ago

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...

romert01 commented 4 years ago

Thank you, greatly appreciate the help!

romert01 commented 4 years ago

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: image (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: image

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: image

I assume this is actually a bug, or perhaps I'm simply extending the package beyond its intended use.

romert01 commented 4 years ago

I would like to follow up on this issue.