From 0794c9fc1e3defdf2f6227b6a59d933198ee30fe Mon Sep 17 00:00:00 2001 From: Marcel Costa <marcelcosta@mcosta.cat> Date: Sat, 5 Feb 2022 10:20:29 +0100 Subject: [PATCH] Se puede excluir una variable del grupo. --- R/ggheatmap.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/ggheatmap.R b/R/ggheatmap.R index 35ebcb3..72d0b94 100644 --- a/R/ggheatmap.R +++ b/R/ggheatmap.R @@ -1,15 +1,20 @@ -ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean"){ +ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL){ if (is.null(x)){x=colnames(df)[1]} if (is.null(y)){y=colnames(df)[2]} if (is.null(value)){value=colnames(df)[3]} df<-rename(df, "VarX"=all_of(x), "VarY"=all_of(y), "Value"=all_of(value)) - + + if (!is.null(exclude_group)){ + df<-df %>% group_by(VarX,VarY) + }else{ + df<-df %>% group_by(VarX,VarY,all_of(exclude_group)) + } if (grouping == "mean"){ - df<-df %>% group_by(VarX,VarY) %>% summarise(Value=mean(Value)) %>% ungroup + df<-df %>% summarise(Value=mean(Value)) %>% ungroup } if (grouping == "median"){ - df<-df %>% group_by(VarX,VarY) %>% summarise(Value=median(Value)) %>% ungroup + df<-df %>% summarise(Value=median(Value)) %>% ungroup } order<-clustsort(df %>% spread(VarY,Value) %>% as.data.frame)