myheat: Draw heatmap usig gplots

View source: R/myheat.R

myheatR Documentation

Draw heatmap usig gplots

Description

hierarchical clustering using amap::Dsit, and draw heatmap using by gplots::heatmap.2. Usinga a categorical data, consists from integer vectors.

Usage

myheat(d, squared, categorical, draw, cden, rden,
c.distm, c.clm, r.distm, r.clm, scale, color, ...)

Arguments

d

data.frame or matrix

squared

logical: squared matrix like a correlation matrix is TRUE. The default value is FALSE

categorical

logical: categorical data or not.

draw

"both","row","column", or "none"

cden

dendrogram object like a result of rsko::extendtree

rden

dendrogram object like a result of rsko::extendtree

c.distm

A distance measure for column side dendrogram. The default value is "spearman". If categorical was TRUE, the default value is "jaccard", and select from these "jaccard", "simpson", "dice" , and "smc".

c.clm

A clustering method for column side dendrogram.

r.distm

A distance measure for row side dendrogram.

r.clm

A clustering method for row side dendrogram.

scale

character "row", "column", "none"

color

character select from "bluered", "greenred", "heat.colors", "BuRd". If categorical was TRUE, colour vectors which lengh same as levels of 'd'.

...

additional optioins for gplots::heatmap.2. E.g. cexRow = 0.8, cexCol = 0.8, labRow = FALSE = F, labCol = F

Examples

## Not run: 
# clustering and draw heatmap
dat = iris[-5]
myheat(d = dat, scale = "column", cexCol = 1)
myheat(d = dat, draw = "both", scale = "column", color = "BuRd", labRow = FALSE, labCol = FALSE)
myheat(d = dat, draw = "both", scale = "column", color = "bluered", cexRow = 0.8, cexCol = 0.8)

# give dendrogram object
rden <- rsko::extendtree(dat = dat, extend = TRUE,
                         distm = "euclidean", clm = "average",
                         lab = as.character(iris[[5]]),
                         gp = iris[,5], vcol = 1:3)

cden <- rsko::extendtree(dat = t(dat), extend = FALSE,
                         distm = "correlation", clm = "average")

myheat(d = t(dat), categorical = FALSE, squared = FALSE, draw = "both",
       cden = rden[[2]], rden = cden[[2]],  scale = "row", cexRow = 0.8)

# squared matrix
cormat <- as.data.frame(cor(t(dat)))
myheat(cormat, squared = TRUE, draw = "both", scale = "none",
c.distm = "correlation", r.distm = "correlation", c.clm = "average", r.clm = "average",
color = "heat.colors")

# categorical data, which converted from character to integer
scale_col <- function(x) as.vector(scale(x, center = min(x), scale = max(x)-min(x)))
fct_col <- function(x) {
   cut(x, breaks = seq(0, 1, 0.25), labels = letters[1:4], include.lowest = TRUE)
   }
dat <- as.data.frame(do.call(cbind, lapply(iris[-5], function(x) { fct_col(scale_col(x))})))
col <- RColorBrewer::brewer.pal(4, "Dark2")
myheat(d=dat, categorical=TRUE, c.distm="smc", r.distm="smc", color=col, cexCol=0.8)


# categorical data
data("listeria", package = "qtl")
dat <- listeria$geno[[1]][[1]]
col <- c("steelblue", "darkseagreen1","violetred2")
rsko::myheat(d=dat, categorical = T, color = col, c.distm="jaccard", r.distm="smc")
legend("topleft", legend = c(levels(factor(dat)),"null"), col = c(col,NA), pch = 15, cex = 0.8)

## End(Not run)


shkonishi/rsko documentation built on Feb. 21, 2023, 5:12 a.m.