From 9ab832c900fa0ce1c9897e02427ba42f557c912d Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Thu, 24 Mar 2022 12:32:48 +0100 Subject: [PATCH] =?UTF-8?q?Soluci=C3=B3n=20de=20alg=C3=BAn=20bug=20con=20e?= =?UTF-8?q?l=20ordenamiento=20de=20elementos=20=3D=3D=201.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/ggheatmap.R | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/R/ggheatmap.R b/R/ggheatmap.R index 15be876..bbaa7b8 100644 --- a/R/ggheatmap.R +++ b/R/ggheatmap.R @@ -17,20 +17,32 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro df<-df %>% summarise(Value=median(Value)) %>% ungroup } - if (length(unique(df$VarX)) > 1 & length(unique(df$VarY)) > 1){ - order<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame) - }else{ - order<-list() - if (length(unique(df$VarX)) > 1){ - xhclust<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame) - order[["x"]]<-pull(xhclust, 1)[hclust(dist(xhclust %>% select(-1)))$order] - }else{order[["x"]]<-df %>% pull(VarX) %>% unique} - if (length(unique(df$VarY)) > 1){ - yhclust<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame) - order[["y"]]<-colnames(yhclust)[2:ncol(yhclust)][hclust(dist(t(yhclust %>% select(-1))))$order] - }else{order[["y"]]<-df %>% pull(VarY) %>% unique} + if (length(unique(df$VarX)) > 1 & length(unique(df$VarY)) > + 1) { + order <- clustsort(df %>% spread(VarY, Value) %>% select(!all_of(exclude_group)) %>% + as.data.frame) + } + else { + order <- list() + if (length(unique(df$VarX)) > 1) { + xhclust <- df %>% spread(VarY, Value) %>% + select(!all_of(exclude_group)) %>% as.data.frame + order[["x"]] <- pull(xhclust, 1)[hclust(dist(xhclust %>% + select(-1)))$order] + } + else { + order[["x"]] <- df %>% pull(VarX) %>% unique + } + if (length(unique(df$VarY)) > 1) { + yhclust <- clustsort(df %>% spread(VarY, Value) %>% + select(!all_of(exclude_group)) %>% as.data.frame) + order[["y"]] <- colnames(yhclust)[2:ncol(yhclust)][hclust(dist(t(yhclust %>% + select(-1))))$order] + } + else { + order[["y"]] <- df %>% pull(VarY) %>% unique + } } - if (scale != "none"){ if (scale == "rows"){