Añadiendo algunas funciones.

This commit is contained in:
Costa
2022-02-04 10:25:01 +01:00
parent 6f4997ee46
commit 6944c24071
5 changed files with 51 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
clustsort<-function(x){
xorder<-pull(x, 1)[hclust(dist(x %>% select(-1)))$order]
yorder<-colnames(x)[2:ncol(x)][hclust(dist(t(x %>% select(-1))))$order]
return(list("x"=xorder,"y"=yorder))
}
+14
View File
@@ -0,0 +1,14 @@
ggheatmap<-function(df, x=NULL, y=NULL, value=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]}
order<-clustsort(df %>% spread(y,value))
df %>%
ggplot(aes(df[,x], df[,y], fill=df[,value]))+
scale_x_discrete(limits=order$x)+
scale_y_discrete(limits=order$y)+
labs(x=x, y=y)+
theme_heatmap()
}
+8
View File
@@ -0,0 +1,8 @@
theme_heatmap<-function(x){
list(geom_tile(),
scale_fill_gradientn(colors=col2(200)),
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=0.5),
panel.background = element_blank(),
axis.ticks = element_blank())
)
}