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)+