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

hotfix row and column ordering when grouping converting them to factors #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5
Version: 1.10.6
Authors@R:
c(person(given = "Stefano",
family = "Mangiola",
Expand Down
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
Loading