# NOT RUN {
# }
# NOT RUN {
set.seed(12345);
simple.data <- data.frame(
'A' = runif(n = 15, min = -1, max = 1),
'B' = runif(n = 15, min = -1, max = 1),
'C' = runif(n = 15, min = -1, max = 1),
'D' = runif(n = 15, min = -1, max = 1),
'E' = runif(n = 15, min = -1, max = 1)
);
create.dotmap(
filename = paste0(tempdir(),'Dotmap_Simple.tiff'),
x = simple.data,
main = 'Simple',
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# create a function to determine the spot sizes (default function works best with values < 1)
spot.size.med <- function(x) {abs(x)/3;}
# Minimal Input
create.dotmap(
filename = paste0(tempdir(),'Dotmap_Minimal_Input.tiff'),
x = microarray[1:5,1:5],
main = 'Minimal input',
spot.size.function = spot.size.med,
xaxis.rot = 90,
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Axes & Labels
spot.size.small <- function(x) {abs(x)/5;}
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_Axes_Labels.tiff'),
x = microarray[1:15,1:15],
main = 'Axes & labels',
spot.size.function = spot.size.small,
# Adjusting the font sizes and labels
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Legend
key.sizes <- seq(2,12,2);
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_Legend.tiff'),
x = microarray[1:15,1:15],
main = 'Legend',
spot.size.function = spot.size.small,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
# Legend for dots
key = list(
space = 'right',
points = list(
cex = spot.size.small(key.sizes),
col = default.colours(2, palette.type = 'dotmap')[2],
pch = 19
),
text = list(
lab = as.character(key.sizes),
cex = 1,
adj = 1
),
padding.text = 3,
background = 'white'
),
key.top = 1,
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Cluster by dots and add dendrogram
plot.data <- microarray[1:15,1:15];
# cluster data
clustered.data <- diana(plot.data);
# order data by cluster
plot.data <- plot.data[clustered.data$order,];
# create dendogram
dendrogram.data <- create.dendrogram(x = plot.data, clustering.method = 'diana',
cluster.dimension = 'row');
dendrogram.grob <- latticeExtra::dendrogramGrob(
x = dendrogram.data,
side = 'right',
type = 'rectangle'
);
# create dotmap
create.dotmap(
x = plot.data,
filename = paste0(tempdir(),'/Dotmap_clustered_dendrogram.tiff'),
main = 'Clustered & dendrogram',
spot.size.function = spot.size.small,
# Adjusting the font sizes and labels
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
legend = list(
right = list(fun = dendrogram.grob)
),
right.padding = 4,
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Add background data
key.sizes <- c(-1, 1);
CNA.colour.function <- function(x){
colours <- rep('white', length(x));
colours[sign(x) == 1] <- 'Red';
colours[sign(x) == -1] <- 'Blue';
colours[x == 0] <- 'transparent';
return(colours);
}
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_with_Background.tiff'),
# added new data for the dots
x = CNA[1:15,1:15],
# Moving the dot-data to be background data
bg.data = microarray[1:15,1:15],
colour.scheme = c('white','black'),
main = 'Background',
spot.size.function = 1,
spot.colour.function = CNA.colour.function,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
key = list(
space = 'right',
points = list(
cex = 1,
col = CNA.colour.function(key.sizes),
pch = 19
),
text = list(
lab = c('Gain', 'Loss'),
cex = 1,
adj = 1
),
title = 'CNA',
padding.text = 2,
background = 'white'
),
# Adding colourkey for background data
colourkey = TRUE,
key.top = 1,
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Discrete background colours
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_Discrete_Background.tiff'),
x = CNA[1:15,1:15],
bg.data = microarray[1:15,1:15],
main = 'Discrete background',
spot.size.function = 1,
spot.colour.function = CNA.colour.function,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
key = list(
space = 'right',
points = list(
cex = 1,
col = CNA.colour.function(key.sizes),
pch = 19
),
text = list(
lab = c('Gain', 'Loss'),
cex = 1,
adj = 1
),
title = 'CNA',
padding.text = 2,
background = 'white'
),
colourkey = TRUE,
key.top = 1,
# Changing background colour scheme
colour.scheme = c('lightyellow','gold','darkorange', 'darkorange3'),
at = seq(0,12,3),
colourkey.labels = seq(0,12,3),
colourkey.labels.at = seq(0,12,3),
bg.alpha = 0.65,
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Dot outlines
border.colours <- function(x){
colours <- rep('transparent', length(x));
colours[x > 0] <- 'black';
colours[x == 0] <- 'transparent';
return(colours);
}
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_Outlined_Dots.tiff'),
x = CNA[1:15,1:15],
bg.data = microarray[1:15,1:15],
main = 'Dot outlines',
spot.size.function = 1,
spot.colour.function = CNA.colour.function,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
key = list(
space = 'right',
points = list(
cex = 1,
col = 'black',
# Remember to also change the pch in the legend
pch = 21,
fill = CNA.colour.function(key.sizes)
),
text = list(
lab = c('Gain', 'Loss'),
cex = 1,
adj = 1
),
title = 'CNA',
padding.text = 2,
background = 'white'
),
colourkey = TRUE,
key.top = 1,
colour.scheme = c('lightyellow','gold','darkorange', 'darkorange3'),
at = seq(0,12,3),
colourkey.labels = seq(0,12,3),
colourkey.labels.at = seq(0,12,3),
bg.alpha = 0.65,
# Change the plotting character to one which has an outline
pch = 21,
pch.border.col = border.colours(CNA[1:15,1:15]),
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Covariates & Legend
sex.colours <- patient$sex[1:15];
sex.colours[sex.colours == 'male'] <- 'dodgerblue';
sex.colours[sex.colours == 'female'] <- 'pink';
sample.covariate <- list(
rect = list(
col = 'black',
fill = sex.colours,
lwd = 1.5
)
);
cov.grob <- covariates.grob(
covariates = sample.covariate,
ord = c(1:15),
side = 'top'
);
sample.cov.legend <- list(
legend = list(
colours = c('dodgerblue', 'pink'),
labels = c('male','female'),
title = 'Sex'
)
);
cov.legend <- legend.grob(
legends = sample.cov.legend
);
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_Covariates.tiff'),
x = CNA[1:15,1:15],
bg.data = microarray[1:15,1:15],
main = 'Covariates',
spot.size.function = 1,
spot.colour.function = CNA.colour.function,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
key = list(
space = 'right',
points = list(
cex = 1,
col = 'black',
pch = 21,
fill = CNA.colour.function(key.sizes)
),
text = list(
lab = c('Gain', 'Loss'),
cex = 1,
adj = 1
),
title = 'CNA',
padding.text = 2,
background = 'white'
),
colourkey = TRUE,
key.top = 1,
colour.scheme = c('lightyellow','gold','darkorange', 'darkorange3'),
at = seq(0,12,3),
colourkey.labels = seq(0,12,3),
colourkey.labels.at = seq(0,12,3),
bg.alpha = 0.65,
pch = 21,
pch.border.col = border.colours(CNA[1:15,1:15]),
# Insert covariates & legend
legend = list(
top = list(
fun = cov.grob
),
left = list(
fun = cov.legend
)
),
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# Side covariates with label
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
)
);
chr.cov.grob <- covariates.grob(
covariates = chr.covariate,
ord = c(1:15),
side = 'right'
);
# create dot legend
dot.grob <- draw.key(
list(
space = 'right',
points = list(
cex = 1,
col = 'black',
pch = 21,
fill = CNA.colour.function(key.sizes)
),
text = list(
lab = c('Gain', 'Loss'),
cex = 1,
adj = 1
),
title = 'CNA',
padding.text = 2,
background = 'white'
)
);
# Setting up the layout for the joint legends
right.layout <- grid.layout(
nrow = 1,
ncol = 2,
width = unit(
x = c(0,1),
units = rep('lines',2)
),
heights = unit(
x = c(1,1),
units = rep('npc', 1)
)
);
right.grob <- frameGrob(layout = right.layout);
right.grob <- packGrob(
frame = right.grob,
grob = chr.cov.grob,
row = 1,
col = 1
);
right.grob <- packGrob(
frame = right.grob,
grob = dot.grob,
row = 1,
col = 2
);
temp <- create.dotmap(
filename = paste0(tempdir(), '/Dotmap_Covariates_Side.tiff'),
x = CNA[1:15,1:15],
bg.data = microarray[1:15,1:15],
main = 'Both covariates',
spot.size.function = 1,
spot.colour.function = CNA.colour.function,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.label = 'Sample',
ylab.label = 'Gene',
xlab.cex = 1,
ylab.cex = 1,
colourkey = TRUE,
key.top = 1,
colour.scheme = c('lightyellow','gold','darkorange', 'darkorange3'),
at = seq(0,12,3),
colourkey.labels = seq(0,12,3),
colourkey.labels.at = seq(0,12,3),
bg.alpha = 0.65,
pch = 21,
pch.border.col = border.colours(CNA[1:15,1:15]),
# insert covariates & legend
legend = list(
right = list(
fun = right.grob
)
),
description = 'Dotmap created by BoutrosLab.plotting.general'
);
# add side label to covariate
print(temp, position = c(0,0,1,1), more = TRUE);
draw.key(
key = list(
text = list(
lab = 'Covariate Label',
cex = 1,
adj = 1
)
),
# position label on the plot
vp = viewport(x = 0.86, y = 0.155, height = 1, width = 0.5, angle = 90),
draw = TRUE
);
dev.off();
# Nature style
create.dotmap(
filename = paste0(tempdir(),'/Dotmap_Nature_style.tiff'),
x = CNA[1:15,1:15],
bg.data = microarray[1:15,1:15],
main = 'Nature style',
spot.size.function = 1,
spot.colour.function = CNA.colour.function,
xaxis.cex = 0.8,
yaxis.cex = 0.8,
xaxis.lab = 1:15,
xlab.cex = 1,
ylab.cex = 1,
key = list(
space = 'right',
points = list(
cex = 1,
col = 'black',
# Remember to also change the pch in the legend
pch = 21,
fill = CNA.colour.function(key.sizes)
),
text = list(
lab = c('Gain', 'Loss'),
cex = 1,
adj = 1
),
title = 'CNA',
padding.text = 2,
background = 'white'
),
colourkey = TRUE,
key.top = 1,
colour.scheme = c('lightyellow','gold','darkorange', 'darkorange3'),
at = seq(0,12,3),
colourkey.labels = seq(0,12,3),
colourkey.labels.at = seq(0,12,3),
bg.alpha = 0.65,
# Change the plotting character to one which has an outline
pch = 21,
pch.border.col = border.colours(CNA[1:15,1:15]),
# set style to Nature
style = 'Nature',
# demonstrating how to italicize character variables
ylab.lab = expression(paste('italicized ', italic('a'))),
# demonstrating how to create en-dashes
xlab.lab = expression(paste('en dashs: 1','\u2013', '10'^'\u2013', ''^3))
);
# }
Run the code above in your browser using DataCamp Workspace