david-barnett / microViz

R package for microbiome data visualization and statistics. Uses phyloseq, vegan and the tidyverse. Docker image available.
https://david-barnett.github.io/microViz/
GNU General Public License v3.0
104 stars 11 forks source link

Heatmap error: heat_palette() palette argument must be either a: vector of colours, or.... #38

Closed Leran10 closed 2 years ago

Leran10 commented 2 years ago

Hi,

I'm trying the example heatmap code on my study,

cols <- distinct_palette(n = 3, add = NA)
names(cols) <- unique(samdat_tbl(psq)$DiseaseState)

psq %>% 
  tax_transform("compositional", rank = "Class") %>% 
  comp_heatmap(
    tax_anno = taxAnnotation(
      Prev. = anno_tax_prev(bar_width = 0.3, size = grid::unit(1, "cm"))
    ),
    sample_anno = sampleAnnotation(
      State1 = anno_sample("DiseaseState"),
      col = list(State1 = cols), border = FALSE,
      State2 = anno_sample_cat("DiseaseState", col = cols)
    )
  ) 

But I kept getting error says:

Error: 
heat_palette() palette argument must be either a:
- vector of colours, or
- palette name from colorspace::hcl_palettes(type = 'diverging')
- palette name from colorspace::divergingx_palettes()
- palette name from colorspace::hcl_palettes(type = 'sequential')

After I added colors = heat_palette(sym = TRUE) after the "sampleAnnotation()" part in comp_heatmap(), the error is gone.

Is this line necessary here or did I misunderstood anything?

Thanks! Leran

david-barnett commented 2 years ago

Does the code run without errors when using the tutorial data?

Additionally, as a general approach, try simplifying the example code to help you (and me) figure out what is causing the error. e.g. does the following work on your dataset, or throw the same error? psq %>% tax_transform("compositional", rank = "Class") %>% comp_heatmap()