Reppo for internal functions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

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
order<- mcor %>% as.data.frame() %>% add_column(Var1=rownames(mcor),.before=1) %>% clustsort
mor<-mcor[order$y, order$x]
mpval<-mpval[order$y, order$x]
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)
if (stat=="signif"){
df.pval$Value<-gtools::stars.pval(df.pval$Value)
}
df$Var1<-factor(df$Var1, levels=order$x)
df$Var2<-factor(df$Var2, levels=order$y)
ggplot(df, aes(Var1, Var2))+
geom_tile(aes(fill=Value), color=color)+
geom_text(data=df.pval, aes(label=Value), color="white")+
scale_fill_gradientn(colors=col2(200))+
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=0.5),
panel.background = element_blank(),
axis.ticks = element_blank())
}