Browse Source

Añadiendo algunas funciones.

main
Costa 2 years ago
parent
commit
6944c24071
5 changed files with 51 additions and 0 deletions
  1. +5
    -0
      R/clustsort.R
  2. +14
    -0
      R/ggheatmap.R
  3. +8
    -0
      R/theme_heatmap.R
  4. +12
    -0
      man/ggheatmap.Rd
  5. +12
    -0
      man/theme_heatmap.Rd

+ 5
- 0
R/clustsort.R

@ -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
- 0
R/ggheatmap.R

@ -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
- 0
R/theme_heatmap.R

@ -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())
)
}

+ 12
- 0
man/ggheatmap.Rd

@ -0,0 +1,12 @@
\name{ggheatmap}
\alias{ggheatmap}
\title{ggheatmap}
\usage{
ggheatmap(x)
}
\description{
Generates a heatmap using ggplot for a dataframe.
}
\examples{
ggheatmap()
}

+ 12
- 0
man/theme_heatmap.Rd

@ -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()
}

Loading…
Cancel
Save