Añadiendo algunas funciones.
This commit is contained in:
@@ -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))
|
||||||
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -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())
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
\name{ggheatmap}
|
||||||
|
\alias{ggheatmap}
|
||||||
|
\title{ggheatmap}
|
||||||
|
\usage{
|
||||||
|
ggheatmap(x)
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Generates a heatmap using ggplot for a dataframe.
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
ggheatmap()
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
\name{theme_heatmap}
|
||||||
|
\alias{theme_heatmap}
|
||||||
|
\title{theme_heatmap}
|
||||||
|
\usage{
|
||||||
|
theme_heatmap()
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Adds geom_tile, color from col2 and theme for heatmap.
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
g+theme_heatmap()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user