Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding empty annotation causes an error #77

Open
halhen opened this issue Jul 21, 2020 · 2 comments
Open

Adding empty annotation causes an error #77

halhen opened this issue Jul 21, 2020 · 2 comments
Labels

Comments

@halhen
Copy link

halhen commented Jul 21, 2020

Adding a covariate with all NA:s causes an error Error in discrete_colors: x >= 1 is not TRUE when plotting.

The error can either be reproduced by adding an annotation with all NA_character_, or by trying a factor with all NA and no levels (this latter case perhaps being a bit weird, but happened to me from working around #75 ).

A workaround is to make the all-NA variable a factor with a dummy level (see example below). Happily, no legend is printed when I do this.

Reproducible example, tested in v 0.4.12.

library(iheatmapr)

A <- matrix(rnorm(6), ncol = 3)
colnames(A) <- c('S1', 'S2', 'S3')
rownames(A) <- c('G1', 'G2')

annotation_0_levels <- data.frame(var = factor(c(NA, NA, NA), levels = c()))
annotation_1_level <- data.frame(var = factor(c(NA, NA, NA), levels = c('')))

# Works
main_heatmap(A) %>%
  add_col_annotation(annotation_1_level)

# Breaks
main_heatmap(A) %>%
  add_col_annotation(annotation_0_levels)
@AliciaSchep
Copy link
Contributor

Seems like the handling of NAs for these functions needs to be examined and maybe adjusted. What is the behavior you would expect for giving all NA values?

@halhen
Copy link
Author

halhen commented Jul 25, 2020

I'd expect the annotation to appear in the plot with all white (NA) colors and the annotation label printed. As for legends/colorbars, I don't have a preference between how the dummy example works (no colors, therefore no legend) or to have a title only legend (for consistency). To save space and since I can argue for it too making sense I'd probably cast a 60:40 vote for the "don't show a legend".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants