From 7d03719bf3b4a13496ea488f804fa8e6d2619967 Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Fri, 4 Feb 2022 13:58:17 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20funci=C3=B3n=20ggcorrplot.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/ggcorrplot.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 R/ggcorrplot.R diff --git a/R/ggcorrplot.R b/R/ggcorrplot.R new file mode 100644 index 0000000..ed4b866 --- /dev/null +++ b/R/ggcorrplot.R @@ -0,0 +1,18 @@ +ggcorrplot<-function(df, var){ + 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) + + order<- mcor %>% as.data.frame() %>% add_column(Var1=rownames(mcor),.before=1) %>% clustsort + + ggplot(df, aes(Var1, Var2, fill=Value))+ + scale_x_discrete(limits=order$x)+ + scale_y_discrete(limits=order$y)+ + theme_heatmap(line.color="black")+ + geom_text(data=df.pval, aes(label=round(Value, 2))) +}