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.

24 lines
740 B

  1. ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean"){
  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 (grouping == "mean"){
  7. df<-df %>% group_by(VarX,VarY) %>% summarise(Value=mean(Value)) %>% ungroup
  8. }
  9. if (grouping == "median"){
  10. df<-df %>% group_by(VarX,VarY) %>% summarise(Value=median(Value)) %>% ungroup
  11. }
  12. order<-clustsort(df %>% spread(VarY,Value) %>% as.data.frame)
  13. df$VarX<-factor(df$VarX, levels=order$x)
  14. df$VarY<-factor(df$VarY, levels=order$y)
  15. df %>%
  16. ggplot(aes(VarX, VarY, fill=Value))+
  17. labs(x=x, y=y)+
  18. theme_heatmap()
  19. }