Skip to content

Commit

Permalink
hotfix row and column ordering when griuping converting them to factors
Browse files Browse the repository at this point in the history
  • Loading branch information
stemangiola committed Jan 13, 2025
1 parent 694f9b0 commit 1ffc2b3
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 281 deletions.
8 changes: 8 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ heatmap_ <-

.data |>

# Hotfix for wrong grouping of elements
# https://github.com/stemangiola/tidyHeatmap/issues/116
# We have to find the root cause ASAP
mutate(
!!.column := as.factor(!!.column),
!!.row := as.factor(!!.row)
) |>

# # Check if data is rectangular
# ifelse_pipe(
# !check_if_data_rectangular((.), !!.column, !!.row, !!.value),
Expand Down
10 changes: 3 additions & 7 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ get_top_left_annotation = function(.data_, .column, .row, .abundance, annotation
ungroup() %>%

mutate(color = map2(annot, idx, ~ {

if(.x %>% class %in% c("factor", "character", "logical")){

# If is colorRamp
Expand All @@ -723,13 +724,8 @@ get_top_left_annotation = function(.data_, .column, .row, .abundance, annotation

# If it is a list of colors
else
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))
}
colorRampPalette(palette_annotation$discrete[[.y]])(length(unique(.x))) %>% setNames(unique(.x))


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

Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.
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.
Loading

0 comments on commit 1ffc2b3

Please sign in to comment.