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.

28 lines
1.1 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. ggplot(df, aes(Var1, Var2))+
  15. scale_x_discrete(limits=order$x)+
  16. scale_y_discrete(limits=order$y)+
  17. geom_tile(aes(fill=Value), color=color)+
  18. geom_text(data=df.pval, aes(label=Value), color="white")+
  19. scale_fill_gradientn(colors=col2(200))+
  20. theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=0.5),
  21. panel.background = element_blank(),
  22. axis.ticks = element_blank())
  23. }