|
@ -1,13 +1,21 @@ |
|
|
ggheatmap<-function(df, x=NULL, y=NULL, value=NULL){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean"){ |
|
|
if (is.null(x)){x=colnames(df)[1]} |
|
|
if (is.null(x)){x=colnames(df)[1]} |
|
|
if (is.null(y)){y=colnames(df)[2]} |
|
|
if (is.null(y)){y=colnames(df)[2]} |
|
|
if (is.null(value)){value=colnames(df)[3]} |
|
|
if (is.null(value)){value=colnames(df)[3]} |
|
|
|
|
|
|
|
|
order<-clustsort(df %>% spread(y,value)) |
|
|
|
|
|
|
|
|
df<-rename(df, "VarX"=x, "VarY"=y, "Value"=value) |
|
|
|
|
|
|
|
|
|
|
|
if (grouping == "mean"){ |
|
|
|
|
|
df<-df %>% group_by(VarX,VarY) %>% summarise(Value=mean(Value)) |
|
|
|
|
|
} |
|
|
|
|
|
if (grouping == "median"){ |
|
|
|
|
|
df<-df %>% group_by(VarX,VarY) %>% summarise(Value=median(Value)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
order<-clustsort(df %>% spread(VarY,Value) %>% as.data.frame) |
|
|
|
|
|
|
|
|
df %>% |
|
|
df %>% |
|
|
ggplot(aes_string(x, y, fill=value))+ |
|
|
|
|
|
|
|
|
ggplot(aes(VarX, VarY, fill=Value))+ |
|
|
scale_x_discrete(limits=order$x)+ |
|
|
scale_x_discrete(limits=order$x)+ |
|
|
scale_y_discrete(limits=order$y)+ |
|
|
scale_y_discrete(limits=order$y)+ |
|
|
labs(x=x, y=y)+ |
|
|
labs(x=x, y=y)+ |
|
|