# NOT RUN {
# }
# NOT RUN {
set.seed(12345);
simple.data <- data.frame(
x <- rnorm(n = 15),
y <- rnorm(n = 15),
z <- rnorm(n = 15),
v <- rnorm(n = 15),
w <- rnorm(n = 15)
);
simple.1D.data <- data.frame(x = rnorm(n = 15));
create.heatmap(
filename = paste0(tempdir(), "/Heatmap_1D_Inside_Legend.tiff"),
x = simple.1D.data,
clustering.method='none',
inside.legend = list(fun = draw.key,
args = list(
key = list(
text = list(
lab = c('test','test','test','test'),
cex = 1,
fontface = 'bold'
),
padding.text = 3,
background = 'white',
alpha.background = 0
)
),
x = 0.5,
y = 0.5
)
)
create.heatmap(
filename = paste0(tempdir(), '/Heatmap_Simple.tiff'),
x = simple.data,
main = 'Simple',
description = 'Heatmap created using BoutrosLab.plotting.general'
);
simple.data.col <- data.frame(
x <- c('blue','green','red','yellow','blue','red','black','white','purple','grey'),
y <- rep('red',10),
z <- rep('yellow',10),
v <- rep('green',10),
w <- rep('purple',10)
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Simple_Using_Colours.tiff'),
x = simple.data.col,
clustering.method = 'none',
input.colours = TRUE
)
# Minimal Input
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Minimal_Input.tiff'),
x = microarray[1:20, 1:20],
main = 'Minimal input',
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Axes and labels
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Axes_Labels.tiff'),
x = microarray[1:20, 1:20],
main = 'Axes & labels',
# Changing axes
xlab.label = 'Genes',
ylab.label = 'Samples',
# Turning on default row and column labels
xaxis.lab = NA,
yaxis.lab = 1:20,
# Adjusting font sizes
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
# Changing colourkey
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Custom Axes
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Custom_Axes.tiff'),
x = microarray[1:20, 1:20],
main = 'Customized axes',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
# Specify where to place tick marks
colourkey.labels.at = c(3,4, 6, 7, 10, 11),
# Specify label colours (note: this is based on the pre-clustering order)
xaxis.col = c('black', 'red',rep('black',6), 'red','black', 'black','red',rep('black',8)),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Two-sided Colour Scheme
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Colour_Scheme_1.tiff'),
x = microarray[1:20, 1:20],
main = 'Colour scheme',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
# Changing the colours
colour.scheme = c('white','firebrick'),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Three-sided Colour Scheme
# Note: when using a three-sided colour scheme, it is advised to have two-sided data
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Colour_Scheme_2.tiff'),
x = microarray[1:20, 1:20],
main = 'Colour scheme',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
# Changing the colours
colour.scheme = c('red','white','turquoise'),
# Scale the data to center around the mean
scale.data = TRUE,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Colour Alpha
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Colour_Alpha.tiff'),
x = microarray[1:20, 1:20],
main = 'Colours alpha',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
# Adjusting the alpha value of the colours
colour.alpha = 'automatic',
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Clustering
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_No_Clustering.tiff'),
x = microarray[1:20, 1:20],
main = 'No clustering',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
# Turning clustering off
clustering.method = 'none',
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Clustering
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Clustering_Methods.tiff'),
x = microarray[1:20, 1:20],
main = 'Clustering methods',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
# Clustering method defaults to 'diana', but can be set to other options
clustering.method = 'complete',
# Also setting the distance measures
rows.distance.method = 'euclidean',
cols.distance.method = 'manhattan',
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Stratified Clustering
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Stratified_Clustering.tiff'),
x = microarray[1:20, 1:20],
main = 'Stratified clustering',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
# Stratifying the clustering by rows
stratified.clusters.rows = list(c(1:10), c(11:20)),
# Adding line to show highlight the division between the two strata
grid.row = TRUE,
row.lines = 10.5,
row.lwd = 2,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Dendrogram provided
col.dendrogram <- BoutrosLab.plotting.general::create.dendrogram(
x = microarray[1:20, 1:20],
cluster.dimension = 'col'
);
row.dendrogram <- BoutrosLab.plotting.general::create.dendrogram(
x = microarray[1:20, 1:20],
cluster.dimension = 'row'
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Dendrogram_Provided.tiff'),
x = microarray[1:20, 1:20],
main = 'Dendrogram provided',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
# note: row/column dendrograms are switched because the function inverts rows and columns
clustering.method = 'none',
row.dendrogram = col.dendrogram,
col.dendrogram = row.dendrogram,
# Adjusting the size of the dendrogram
right.dendrogram.size = 3,
top.dendrogram.size = 2.5,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Covariates and Legends
# Note: covariates can also be added using the create.multiplot function
# set the colour schemes for the covariates
sex.colours <- patient$sex;
sex.colours[sex.colours == 'male'] <- 'dodgerblue';
sex.colours[sex.colours == 'female'] <- 'pink';
stage.colours <- patient$stage;
stage.colours[stage.colours == 'I'] <- 'plum1';
stage.colours[stage.colours == 'II'] <- 'orchid1';
stage.colours[stage.colours == 'III'] <- 'orchid3';
stage.colours[stage.colours == 'IV'] <- 'orchid4';
# create an object to draw the covariates from
sample.covariate <- list(
rect = list(
col = 'black',
fill = sex.colours,
lwd = 1.5
),
rect = list(
col = 'black',
fill = stage.colours,
lwd = 1.5
)
);
# create a legend for the covariates
sample.cov.legend <- list(
legend = list(
colours = c('dodgerblue', 'pink'),
labels = c('male','female'),
title = 'Sex'
),
legend = list(
colours = c('plum1', 'orchid1','orchid3', 'orchid4'),
labels = c('I','II', 'III', 'IV'),
title = 'Stage'
)
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Covariates_Simple.tiff'),
x = microarray[1:20, 1:20],
main = 'Covariates',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
# adding covariates and corresponding legend
covariates = sample.covariate,
covariate.legend = sample.cov.legend,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Top covariate and legend customization
chr.cov.colours <- microarray$Chr;
chr.cov.colours[microarray$Chr == 1] <- default.colours(3, palette.type = 'chromosomes')[1];
chr.cov.colours[microarray$Chr == 2] <- default.colours(3, palette.type = 'chromosomes')[2];
chr.cov.colours[microarray$Chr == 3] <- default.colours(3, palette.type = 'chromosomes')[3];
chr.covariate <- list(
rect = list(
col = 'white',
fill = chr.cov.colours,
lwd = 1.5
)
);
# join covariate legends
combo.cov.legend <- list(
legend = list(
colours = default.colours(3, palette.type = 'chromosomes'),
labels = c('1','2', '3'),
title = 'Chromosome',
border = 'white'
),
legend = list(
colours = c('dodgerblue', 'pink'),
labels = c('male','female'),
title = 'Sex'
),
legend = list(
colours = c('plum1', 'orchid1','orchid3', 'orchid4'),
labels = c('I','II', 'III', 'IV'),
title = 'Stage'
)
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Covariate_Legend_Custom.tiff'),
x = microarray[1:20, 1:20],
main = 'Custom covariates & legend',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
clustering.method = 'none',
# side covariate
covariates = sample.covariate,
# top covariate and covariate border specification
covariates.top = chr.covariate,
covariate.legend = combo.cov.legend,
# making outline of border a matching green
covariates.top.grid.border = list(col = 'lightblue', lwd = 2),
# making certain column divisions a different colour
covariates.top.col.lines = c(5,6),
covariates.top.grid.col = list(col = 'blue', lwd = 2),
# legend customization
legend.side = c('right','left','top'),
legend.title.cex = 0.75,
legend.cex = 0.75,
legend.title.just = 'left',
legend.border = list(lwd = 1),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Custom gridlines
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Gridlines.tiff'),
x = microarray[1:20, 1:20],
main = 'Gridlines',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
# colouring gridlines
grid.row = TRUE,
grid.col = TRUE,
row.colour = 'white',
col.colour = 'white',
row.lwd = 1.5,
col.lwd = 1.5,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Label cells
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Labelled_Cells.tiff'),
x = microarray[1:20, 1:20],
main = 'Labelled cells',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
grid.row = TRUE,
grid.col = TRUE,
row.colour = 'white',
col.colour = 'white',
row.lwd = 1.5,
col.lwd = 1.5,
clustering.method = 'none',
# conditionally labelling cells
# flipping rows and columns because the heatmap function does so
row.pos = which(microarray[1:20, 1:20] > 11, arr.ind = TRUE)[,2],
col.pos = which(microarray[1:20, 1:20] > 11, arr.ind = TRUE)[,1],
cell.text = microarray[1:20, 1:20][microarray[1:20, 1:20] > 11],
text.col = 'white',
text.cex = 0.65,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Label cells
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Labelled_Cells_NPC.tiff'),
x = microarray[1:20, 1:20],
main = 'Labelled cells',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
grid.row = TRUE,
grid.col = TRUE,
row.colour = 'white',
col.colour = 'white',
row.lwd = 1.5,
col.lwd = 1.5,
clustering.method = 'none',
text.use.grid.coordinates = FALSE,
# conditionally labelling cells
# flipping rows and columns because the heatmap function does so
cell.text = c("text1","text2"),
text.col = 'white',
text.cex = 0.65,
text.position = list(c(0.5,0.5),c(0.75,0.75)),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Method 1 of adding symbols (very similar to how text is added)
points <- microarray[1:20, 1:20][microarray[1:20, 1:20] > 11];
size.from <- range(points, na.rm = TRUE);
size.to <- c(1,3);
point.size <- (points - size.from[1])/diff(size.from) * diff(size.to) + size.to[1];
point.colour <- grey(runif(sum(microarray[1:20, 1:20] > 11), max = 0.5));
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Symbols_1.tiff'),
x = microarray[1:20, 1:20],
main = 'Symbols',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
clustering.method = 'none',
# conditionally adding points to cells
# flipping rows and columns because the heatmap function does so
row.pos = which(microarray[1:20, 1:20] > 11, arr.ind = TRUE)[,2],
col.pos = which(microarray[1:20, 1:20] > 11, arr.ind = TRUE)[,1],
cell.text = rep(expression("\u25CF"), times = sum(microarray[1:20, 1:20] > 11)),
text.col = point.colour,
text.cex = point.size,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Method 2 of Adding Symbols
# Create matrices to describe the symbols
circle.matrix <- matrix(
nrow = 20,
ncol = 20,
data = FALSE
);
circle.colour.matrix <- matrix(
nrow = 20,
ncol = 20,
data = 'pink'
);
circle.size.matrix <- matrix(
nrow = 20,
ncol = 20,
data = 20
);
border.matrix <- matrix(
nrow = 20,
ncol = 20,
data = FALSE
);
border.colour.matrix <- matrix(
nrow = 20,
ncol = 20,
data = 'black'
);
border.size.matrix <- matrix(
nrow = 20,
ncol = 20,
data = 4
);
square.matrix <- matrix(
nrow = 20,
ncol = 20,
data = FALSE
);
square.colour.matrix <- matrix(
nrow = 20,
ncol = 20,
data = 'pink'
);
square.size.matrix <- matrix(
nrow = 20,
ncol = 20,
data = 10
);
# setting up the symbols
symbol.locations <- list(
circles = list(
list(
x = circle.matrix,
col = circle.colour.matrix,
size = circle.size.matrix
)
),
borders = list(
list(
x = border.matrix,
col = border.colour.matrix,
size = border.size.matrix
),
# creating a border encompassing a larger area
list(
xright = 12.10,
xleft = 12,
ybottom = 1,
ytop = 20,
size = 4,
col = 'pink'
)
),
squares = list(
list(
x = square.matrix,
col = square.colour.matrix,
size = square.size.matrix
)
)
);
# Set which items in the matrix will be shown
# symbol.locations$borders[[1]]$x <- FALSE;
# symbol.locations$squares[[1]]$x <- FALSE;
symbol.locations$circles[[1]]$x[which(microarray[1:20,1:20] > 11, arr.ind = TRUE)] <- TRUE;
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Symbols_2.tiff'),
x = microarray[1:20, 1:20],
main = 'Symbols',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
clustering.method = 'none',
# adding symbols
symbols = symbol.locations,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Rotate matrix
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Rotated_Matrix.tiff'),
x = microarray[1:20, 1:20],
main = 'Rotated matrix',
# Also flip labels
ylab.label = 'Genes',
xlab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = NA,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
colourkey.labels.at = seq(2,12,1),
colour.alpha = 'automatic',
grid.row = TRUE,
grid.col = TRUE,
row.colour = 'white',
col.colour = 'white',
row.lwd = 1.5,
col.lwd = 1.5,
# stop heatmap function from rotating matrix
same.as.matrix = TRUE,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Example of using discrete data
discrete.data <- microarray[1:10,1:40];
# Looking for values greater than 10
discrete.data[which(discrete.data < 10, arr.ind = TRUE)] <- 0;
discrete.data[which(discrete.data > 0, arr.ind = TRUE)] <- 1;
sex.colour <- recode.vector(
patient$sex,
list(
dodgerblue = 'male',
pink = 'female'
)
);
stage.colour <- recode.vector(
patient$stage,
list(
plum1 = 'I',
orchid1 = 'II',
orchid3 = 'III',
orchid4 = 'IV'
)
);
msi.colour <- recode.vector(
patient$msi,
list(
chartreuse4 = 'MSS',
chartreuse2 = 'MSI-High'
)
);
discrete.covariate <- list(
rect = list(
col = 'transparent',
fill = sex.colour,
lwd = 1.5
),
rect = list(
col = 'transparent',
fill = stage.colour,
lwd = 1.5
),
rect = list(
col = 'transparent',
fill = msi.colour,
lwd = 1.5
)
);
discrete.covariate.legend <- list(
legend = list(
colours = c('dodgerblue', 'pink'),
labels = c('male','female'),
title = expression(underline('Sex'))
),
legend = list(
colours = c('plum1', 'orchid1', 'orchid3', 'orchid4'),
labels = c('I','II', 'III', 'IV'),
title = expression(underline('Stage'))
),
legend = list(
colours = c('chartreuse4', 'chartreuse2'),
labels = c('MSS','MSI-High'),
title = expression(underline('MSI'))
)
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Discrete_Data.tiff'),
x = discrete.data,
main = 'Discrete data',
xlab.label = 'Samples',
same.as.matrix = TRUE,
# Customize plot
clustering.method = 'none',
total.colours = 3,
colour.scheme = c('white','black'),
fill.colour = 'grey95',
# Changing axes
xat = seq(0,40,5),
xaxis.lab = seq(0,40,5),
yaxis.lab = rownames(microarray)[1:10],
yaxis.cex = 0.75,
xaxis.cex = 0.75,
xaxis.rot = 0,
xlab.cex = 1,
# Covariates
covariates.top = discrete.covariate,
covariate.legend = discrete.covariate.legend,
legend.side = 'right',
legend.title.cex = 0.75,
legend.cex = 0.75,
legend.title.just = 'left',
legend.between.row = 0.2,
legend.border = list(col = 'transparent'),
legend.border.padding = 2,
shrink = 0.7,
covariates.top.grid.border = list(col = 'black', lwd = 2),
scale.data = FALSE,
print.colour.key = FALSE,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Correlation matrix
# Example of how to visualize the relationship between (e.x.) different cellularity estimates
# Generate a correlation matrix
cor.data <- cor(t(microarray[1:10,1:10]), method = 'spearman');
colnames(cor.data) <- colnames(microarray)[1:10];
# ensure that input data matrix is equal to what the heatmap clustering produces
distance.matrix <- as.dist(1 - cor(t(cor.data), use = "pairwise", method = "pearson"));
clustered.order <- hclust(d = distance.matrix, method = "ward")$order;
cor.data <- cor.data[clustered.order, clustered.order];
# prepare labels
x <- round(cor.data, 2);
x[x == 1] <- colnames(x);
y <- x;
for (i in 1:(ncol(y)-1)) {
y[i, (i+1):nrow(y)] <- "";
};
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Cellularity_Estimates.tiff'),
x = cor.data,
main = 'Correlation matrix',
xaxis.lab = NULL,
yaxis.lab = NULL,
cell.text = y,
clustering.method = 'ward',
plot.dendrograms = 'none',
rows.distance.method = 'correlation',
cols.distance.method = 'correlation',
cor.method = 'pearson',
col.pos = which(y != '1', arr.ind = TRUE)[,1],
row.pos = which(y != '1', arr.ind = TRUE)[,2],
text.fontface = 2,
text.col = 'white',
text.cex = 0.70,
colourkey.cex = 1,
colour.scheme = c('blue', 'darkgrey', 'brown'),
colour.centering.value = 0,
at = seq(-1, 1, 0.001),
colour.alpha = 1.5,
grid.row = TRUE,
grid.col = TRUE,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Discrete sequential colours
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Discrete_Colours_Sequential.tiff'),
x = microarray[1:20, 1:20],
main = 'Discrete colours',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
# Adjusting total colours plotted
colourkey.labels.at = seq(2,12,1),
at = seq(2,12,1),
# Add one to account for a 'null' colour
total.colours = 11,
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Discrete qualitative colours
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Discrete_Colours_Qualitative.tiff'),
x = microarray[1:20, 1:20],
main = 'Discrete colours',
xlab.label = 'Genes',
ylab.label = 'Samples',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
# Adjusting total colours plotted
colourkey.labels.at = seq(2,12,1),
colourkey.labels = seq(2,12,1),
at = seq(2,12,1),
# Add one to account for a 'null' colour
total.colours = 11,
colour.scheme = default.colours(10),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# Nature style
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_Nature_style.tiff'),
x = microarray[1:20, 1:20],
main = 'Nature style',
xaxis.lab = NA,
yaxis.lab = 1:20,
xaxis.cex = 0.75,
yaxis.cex = 0.75,
xaxis.fontface = 1,
yaxis.fontface = 1,
colourkey.cex = 1,
# Adjusting total colours plotted
colourkey.labels.at = seq(2,12,1),
colourkey.labels = seq(2,12,1),
at = seq(2,12,1),
# Add one to account for a 'null' colour
total.colours = 11,
colour.scheme = default.colours(10),
# set style to Nature
style = 'Nature',
# demonstrating how to italicize character variables
ylab.label = expression(paste('italicized ', italic('a'))),
# demonstrating how to create en-dashes
xlab.label = expression(paste('en dashs: 1','\u2013', '10'^'\u2013', ''^3)),
description = 'Heatmap created using BoutrosLab.plotting.general'
);
# create heatmap with key like legend - used to show range of continuous variables
# First create legend with discrete colours
sex.colour <- recode.vector(
patient$sex,
list(
dodgerblue = 'male',
pink = 'female'
)
);
stage.colour <- recode.vector(
patient$stage,
list(
plum1 = 'I',
orchid1 = 'II',
orchid3 = 'III',
orchid4 = 'IV'
)
);
msi.colour <- recode.vector(
patient$msi,
list(
chartreuse4 = 'MSS',
chartreuse2 = 'MSI-High'
)
);
discrete.covariate <- list(
rect = list(
col = 'transparent',
fill = sex.colour,
lwd = 1.5
),
rect = list(
col = 'transparent',
fill = stage.colour,
lwd = 1.5
),
rect = list(
col = 'transparent',
fill = msi.colour,
lwd = 1.5
)
);
discrete.covariate.legend <- list(
legend = list(
colours = c('dodgerblue', 'pink'),
labels = c('male','female'),
title = expression(underline('Sex'))
),
legend = list(
colours = c('plum1', 'orchid1', 'orchid3', 'orchid4'),
labels = c('I','II', 'III', 'IV'),
title = expression(underline('Stage'))
),
legend = list(
colours = c('chartreuse4', 'chartreuse2'),
labels = c('MSS','MSI-High'),
title = expression(underline('MSI'))
),
legend = list(
colours = c('grey0', 'grey100'),
labels = c('want key like','legend here'),
title = expression(underline('one')),
continuous = TRUE,
height=3
),
legend = list(
colours = c('grey0', 'grey100'),
labels = c('want key like','legend here'),
title = expression(underline('two'))
),
legend = list(
colours = c('grey0', 'grey100'),
labels = c(0,10),
title = expression(underline('three')),
continuous = TRUE,
width = 3,
tck = 1,
tck.number = 3,
at = c(0,100),
angle = -90,
just = c("center","bottom")
)
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_ContinuousVariablesKey.tiff'),
x = patient[1:20, 4:6],
xlab.label = 'Samples',
ylab.label = 'Scaled Data',
xaxis.cex = 0.75,
yaxis.cex = 0.75,
clustering.method = 'none',
print.colour.key = FALSE,
scale=TRUE,
same.as.matrix = FALSE,
covariates.top = discrete.covariate,
covariates.top.grid.row = list(lwd = 1),
covariate.legends = discrete.covariate.legend,
legend.title.just = 'left',
colour.scheme = c('gray0','grey100'),
fill.colour = 'grey95',
axis.xlab.padding = 1.5
);
create.heatmap(
filename = paste0(tempdir(),'/Heatmap_borderRemoved.tiff'),
x = simple.data,
main = 'Simple',
description = 'Heatmap created using BoutrosLab.plotting.general',
axes.lwd = 0
);
# }
Run the code above in your browser using DataLab