Añadida a la función ggheatmap la posibilidad de colorear las líneas.
This commit is contained in:
+10
-6
@@ -1,10 +1,10 @@
|
||||
ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none"){
|
||||
ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none",color="#FFFFFF00"){
|
||||
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{
|
||||
@@ -17,7 +17,7 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro
|
||||
df<-df %>% summarise(Value=median(Value)) %>% ungroup
|
||||
}
|
||||
order<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame)
|
||||
|
||||
|
||||
if (scale != "none"){
|
||||
if (scale == "rows"){
|
||||
cols<-unique(df$VarY)
|
||||
@@ -32,12 +32,16 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro
|
||||
df<-gather(sca.df, VarX, Value, all_of(cols))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
geom_tile(aes(fill=Value), color=color)+
|
||||
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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user