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.

29 lines
851 B

  1. ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL){
  2. if (is.null(x)){x=colnames(df)[1]}
  3. if (is.null(y)){y=colnames(df)[2]}
  4. if (is.null(value)){value=colnames(df)[3]}
  5. df<-rename(df, "VarX"=all_of(x), "VarY"=all_of(y), "Value"=all_of(value))
  6. if (!is.null(exclude_group)){
  7. df<-df %>% group_by(VarX,VarY)
  8. }else{
  9. df<-df %>% group_by(VarX,VarY,all_of(exclude_group))
  10. }
  11. if (grouping == "mean"){
  12. df<-df %>% summarise(Value=mean(Value)) %>% ungroup
  13. }
  14. if (grouping == "median"){
  15. df<-df %>% summarise(Value=median(Value)) %>% ungroup
  16. }
  17. order<-clustsort(df %>% spread(VarY,Value) %>% as.data.frame)
  18. df$VarX<-factor(df$VarX, levels=order$x)
  19. df$VarY<-factor(df$VarY, levels=order$y)
  20. df %>%
  21. ggplot(aes(VarX, VarY, fill=Value))+
  22. labs(x=x, y=y)+
  23. theme_heatmap()
  24. }