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.

31 lines
1.2 KiB

  1. ggcorrplot<-function(df, var, color="#FFFFFF00", stat="signif"){
  2. m.df<-df %>% spread(Cyt, Value) %>% select(-pats)
  3. mcor<-cor(m.df, m.df, use="pairwise.complete.obs") # Por defecto usa el método de Pearson.
  4. mpval<-Hmisc::rcorr(as.matrix(m.df))$P
  5. df<-mcor %>% as.data.frame() %>% add_column(Var1=rownames(mcor),.before=1) %>%
  6. gather(Var2, Value, -Var1)
  7. df.pval<-mpval %>% as.data.frame() %>% add_column(Var1=rownames(mpval),.before=1) %>%
  8. gather(Var2, Value, -Var1)
  9. df.pval$Value<-round(df.pval$Value, 3)
  10. if (stat=="signif"){
  11. df.pval$Value<-gtools::stars.pval(df.pval$Value)
  12. }
  13. order<- mcor %>% as.data.frame() %>% add_column(Var1=rownames(mcor),.before=1) %>% clustsort
  14. df$Var1<-factor(df$Var1, levels=order$x)
  15. df$Var2<-factor(df$Var2, levels=order$y)
  16. ggplot(df, aes(Var1, Var2))+
  17. # scale_x_discrete(limits=order$x)+
  18. # scale_y_discrete(limits=order$y)+
  19. geom_tile(aes(fill=Value), color=color)+
  20. geom_text(data=df.pval, aes(label=Value), color="white")+
  21. scale_fill_gradientn(colors=col2(200))+
  22. theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=0.5),
  23. panel.background = element_blank(),
  24. axis.ticks = element_blank())
  25. }