| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -17,20 +17,32 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    df<-df %>% summarise(Value=median(Value)) %>% ungroup | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  if (length(unique(df$VarX)) > 1 & length(unique(df$VarY)) > 1){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    order<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  }else{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    order<-list() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (length(unique(df$VarX)) > 1){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      xhclust<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      order[["x"]]<-pull(xhclust, 1)[hclust(dist(xhclust %>% select(-1)))$order] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }else{order[["x"]]<-df %>% pull(VarX) %>% unique} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (length(unique(df$VarY)) > 1){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      yhclust<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      order[["y"]]<-colnames(yhclust)[2:ncol(yhclust)][hclust(dist(t(yhclust %>% select(-1))))$order] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }else{order[["y"]]<-df %>% pull(VarY) %>% unique} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  if (length(unique(df$VarX)) > 1 & length(unique(df$VarY)) > | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    order <- clustsort(df %>% spread(VarY, Value) %>% select(!all_of(exclude_group)) %>% | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                         as.data.frame) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    order <- list() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (length(unique(df$VarX)) > 1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      xhclust <- df %>% spread(VarY, Value) %>% | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        select(!all_of(exclude_group)) %>% as.data.frame | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      order[["x"]] <- pull(xhclust, 1)[hclust(dist(xhclust %>% | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                                     select(-1)))$order] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      order[["x"]] <- df %>% pull(VarX) %>% unique | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (length(unique(df$VarY)) > 1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      yhclust <- clustsort(df %>% spread(VarY, Value) %>% | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                             select(!all_of(exclude_group)) %>% as.data.frame) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      order[["y"]] <- colnames(yhclust)[2:ncol(yhclust)][hclust(dist(t(yhclust %>% | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                                                         select(-1))))$order] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      order[["y"]] <- df %>% pull(VarY) %>% unique | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  if (scale != "none"){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (scale == "rows"){ | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
 |