From eeba7ea855ba5051718b2c6da4a26a8091b48fcc Mon Sep 17 00:00:00 2001 From: Marcel Costa Date: Sat, 5 Feb 2022 16:47:08 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20opci=C3=B3n=20de=20escalado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/ggheatmap.R | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/R/ggheatmap.R b/R/ggheatmap.R index 7d527b8..2ed6c91 100644 --- a/R/ggheatmap.R +++ b/R/ggheatmap.R @@ -1,4 +1,4 @@ -ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL){ +ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none"){ if (is.null(x)){x=colnames(df)[1]} if (is.null(y)){y=colnames(df)[2]} if (is.null(value)){value=colnames(df)[3]} @@ -21,6 +21,21 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro df$VarX<-factor(df$VarX, levels=order$x) df$VarY<-factor(df$VarY, levels=order$y) + if (scale != "none"){ + if (scale == "rows"){ + cols<-unique(df$VarY) + sca.df<-spread(df, VarY, Value) + for (i in cols){sca.df[,i]<-scale(sca.df[,i])} + df<-gather(sca.df, VarY, Value, all_of(cols)) + } + if (scale == "cols"){ + cols<-unique(df$VarX) + sca.df<-spread(df, VarX, Value) + for (i in cols){sca.df[,i]<-scale(sca.df[,i])} + df<-gather(sca.df, VarX, Value, all_of(cols)) + } + } + df %>% ggplot(aes(VarX, VarY, fill=Value))+ labs(x=x, y=y)+