View source: R/make.pheatmap.R
make.pheatmap | R Documentation |
This function allows you to create a coloured heatmap for clusters vs markers (coloured by MFI) or clusters vs samples (coloured by MFI or cell counts). Can be set to plot 'fold-change' values (with is.fold = TRUE) that are provided in log2. make.pheatmap is a wrapper around the pheatmap function from pheatmap. Also uses the packages 'RColorBrewer' and 'scales' for colour customisation.
make.pheatmap(dat, sample.col, plot.cols, annot.cols, file.name,
plot.title, transpose, is.fold, fold.range, normalise, dendrograms,
row.sep, col.sep, cell.size, standard.colours, path)
dat |
NO DEFAULT. data.frame. Clusters/populations vs markers (MFI) or Clusters/populations vs samples or (MFI or cell numbers). |
sample.col |
NO DEFAULT. Character. Specify the name of the column that indicates samples. Will be rows on heatmap. |
plot.cols |
NO DEFAULT. Character vector. Name of columns you wish to plot on the heatmap. Will be columns on heatmap. |
annot.cols |
DEFAULT = NULL. Character. Columns which contain values that you do NOT want to plot in the heatmap, e.g. sample name, group name, Live/Dead etc. |
file.name |
DEFAULT = paste0("Pheatmap by ", sample.col, ".png"). Character. What do you want to call the file, including the extension. |
plot.title |
DEFAULT = paste0(sample.col, " heatmap"). Character. |
transpose |
DEFAULT = FALSE. Logical. Do you want to transpose the heatmap. |
normalise |
DEFAULT = TRUE. Logical. Only applies to standard heatmaps (i.e. when is.fold = FALSE). TRUE to normalise each column between 0 and 1, FALSE to plot the raw values. |
is.fold |
DEFAULT = FALSE. Logical. TRUE for fold-change heatmap, FALSE for normal values heatmap. |
fold.range |
DEFAULT = NULL. Numeric vector. For fold-change heatmaps, what is the maxium and minimum values that should be plotted. Example: for a max of 3, and a minimum of -3 would b c(3,-3). Defaults to NULL (which will use the max and min within the dataset). |
dendrograms |
DEFAULT = "both". Character. Do you want to include dendrograms on columns/rows. Can be "both", "row", "column", or "none. |
cutree_rows |
DEFAULT = 1 (i.e. no divisions). Divides rows based on the level of dendrogram branches, if dendrograms = 'both' or 'row'. |
cutree_cols |
DEFAULT = 1 (i.e. no divisions). Divides columns based on the level of dendrogram branches, if dendrograms = 'both' or 'column' |
row.sep |
DEFAULT = c(). Numeric. Only used if not clustering rows. |
col.sep |
DEFAULT = c(). Numeric. Only used if not clustering columns |
cell.size |
DEFAULT = 15. Numeric. |
standard.colours |
DEFAULT = "BuPu". Character. Can also be "RdYlBu", "YlGnBu", "viridis", "magma", "inferno", "spectral", "Blues", "Reds", "Greys", or "rev(RdBu)". |
fold.colours |
DEFAULT = "Spectre". Character, a custom blue:black:red fold-change colour scheme. Can also be "RdYlBu", "YlGnBu", "viridis", "magma", "inferno", "spectral", "Blues", "Reds", "Greys", or "rev(RdBu)". |
path |
DEFAULT = NULL. The location to save plots. By default, will save to current working directory. Can be overidden by entering a sub-directory name (e.g. if you have a subdirectory under your working directory called 'plots', you can enter this here). |
Thomas M Ashhurst, thomas.ashhurst@sydney.edu.au Felix Marsh-Wakefield, felix.marsh-wakefield@sydney.edu.au
https://sydneycytometry.org.au/spectre. Helpful examples at https://davetang.org/muse/2018/05/15/making-a-heatmap-in-r-with-the-pheatmap-package/
# Create some sample data
library(data.table)
dat <- Spectre::demo.clustered
## MFI cluster vs marker heatmap
# mock MFI data per sample, population.
demo.exp <- Spectre::demo.clustered[, lapply(.SD, mean), .SDcols = c("CD45_asinh", "Ly6G_asinh", "CD11b_asinh", "B220_asinh", "CD8a_asinh"), by = Population]
Spectre::make.pheatmap(dat = demo.exp,
file.name = "Expression pheatmap.png",
plot.title = "Expression",
sample.col = "Population",
plot.cols = c("CD45_asinh", "Ly6G_asinh", "CD11b_asinh", "B220_asinh", "CD8a_asinh"))
# create mock population count per sample
demo.sum <- Spectre::demo.clustered[, .(count = .N), by = c("Sample", "Population", "Group", "Batch")]
demo.sum <- dcast(demo.sum, Sample+Group+Batch ~ Population, value.var='count')
## Z-scrore of fold-change type heatmap
z.dat <- do.zscore(dat = demo.sum,
use.cols = c("CD4 T cells", "CD8 T cells", "Infil Macrophages", "Microglia", "NK cells", "Neutrophils"),
replace = TRUE)
Spectre::make.pheatmap(dat = z.dat,
file.name = "z-score.png",
plot.title = "z-score",
sample.col = "Sample",
plot.cols = c("CD4 T cells", "CD8 T cells", "Infil Macrophages", "Microglia", "NK cells", "Neutrophils"),
annot.cols = c("Group", "Batch"),
is.fold = TRUE,
fold.range = c(3,-3)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.