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

ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL){
if (is.null(x)){x=colnames(df)[1]}
if (is.null(y)){y=colnames(df)[2]}
if (is.null(value)){value=colnames(df)[3]}
df<-rename(df, "VarX"=all_of(x), "VarY"=all_of(y), "Value"=all_of(value))
if (!is.null(exclude_group)){
df<-df %>% group_by(VarX,VarY)
}else{
df<-df %>% group_by(VarX,VarY,all_of(exclude_group))
}
if (grouping == "mean"){
df<-df %>% summarise(Value=mean(Value)) %>% ungroup
}
if (grouping == "median"){
df<-df %>% summarise(Value=median(Value)) %>% ungroup
}
order<-clustsort(df %>% spread(VarY,Value) %>% as.data.frame)
df$VarX<-factor(df$VarX, levels=order$x)
df$VarY<-factor(df$VarY, levels=order$y)
df %>%
ggplot(aes(VarX, VarY, fill=Value))+
labs(x=x, y=y)+
theme_heatmap()
}