From d51fe8a64d88c43ef6ca822efdaf58d67e2fb83a Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Fri, 4 Feb 2022 15:32:12 +0100 Subject: [PATCH] He empezado a incorporar el triangular la matriz. --- R/ggcorrplot.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/ggcorrplot.R b/R/ggcorrplot.R index 2c42856..d26e5b4 100644 --- a/R/ggcorrplot.R +++ b/R/ggcorrplot.R @@ -1,12 +1,21 @@ -ggcorrplot<-function(df, var, color="#FFFFFF00", stat="signif"){ +ggcorrplot<-function(df, var, color="#FFFFFF00", stat="signif", tri="all"){ m.df<-df %>% spread(Cyt, Value) %>% select(-pats) mcor<-cor(m.df, m.df, use="pairwise.complete.obs") # Por defecto usa el método de Pearson. mpval<-Hmisc::rcorr(as.matrix(m.df))$P - df<-mcor %>% as.data.frame() %>% add_column(Var1=rownames(mcor),.before=1) %>% - gather(Var2, Value, -Var1) - df.pval<-mpval %>% as.data.frame() %>% add_column(Var1=rownames(mpval),.before=1) %>% - gather(Var2, Value, -Var1) + df<-mcor %>% as.data.frame() + if (tri == "lower"){ + df[lower.tri(df, diag=T)]<-NA + } + df<-df %>% add_column(Var1=rownames(mcor),.before=1) %>% + gather(Var2, Value, -Var1) %>% filter(!is.na(Value)) + + df.pval<-mpval %>% as.data.frame() + if (tri == "lower"){ + df.pval[lower.tri(df.pval, diag=T)]<-NA + } + df.pval<-df.pval %>% add_column(Var1=rownames(mpval),.before=1) %>% + gather(Var2, Value, -Var1) %>% filter(!is.na(Value)) df.pval$Value<-round(df.pval$Value, 3)