Skip to content

Commit

Permalink
Merge pull request #131 from william-hutchison/fix-factor-colour
Browse files Browse the repository at this point in the history
Fix factor colour
  • Loading branch information
stemangiola committed Aug 5, 2024
2 parents 68db595 + 9c227c7 commit 5d9409e
Show file tree
Hide file tree
Showing 12 changed files with 1,199 additions and 109 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: tidyHeatmap
Title: A Tidy Implementation of Heatmap
Version: 1.10.1
Version: 1.10.3
Authors@R:
c(person(given = "Stefano",
family = "Mangiola",
Expand Down
3 changes: 3 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Specify undefined global variables for R CMD check
utils::globalVariables(c("shape", "size", "text", ":="))

#the class definition
InputHeatmap<-setClass(
"InputHeatmap",
Expand Down
9 changes: 8 additions & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,14 @@ get_top_left_annotation = function(.data_, .column, .row, .abundance, annotation

# If it is a list of colors
else
colorRampPalette(palette_annotation$discrete[[.y]])(length(unique(.x))) %>% setNames(unique(.x))
if (is(.x, "factor")) {
color_vector <- palette_annotation$discrete[[.y]] %>% setNames(levels(.x))
color_vector[!is.na(names(color_vector))]

} else {
colorRampPalette(palette_annotation$discrete[[.y]])(length(unique(.x))) %>% setNames(unique(.x))
}

} else if (.x %>% class %in% c("integer", "numerical", "numeric", "double")){

# If is colorRamp
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/tests/grouped-annotated-heatmap-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions tests/testthat/_snaps/tests/grouped-custom-color-both.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 33 additions & 33 deletions tests/testthat/_snaps/tests/legend.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5d9409e

Please sign in to comment.