# NOT RUN {
set.seed(12345);
simple.data <- data.frame(
x <- rnorm(10000),
y <- rnorm(10000)
);
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Simple.tiff'),
formula = y ~ x,
data = simple.data,
main = 'Simple',
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Set up data
hexbin.data <- data.frame(
x = microarray[,1],
y = microarray[,2]
);
# Minimal Input
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Minimal_Input.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Minimal input',
# formatting bins
colourcut = seq(0, 1, length = 11),
# this sets the maximum value plotted -- values greater than this will not appear
maxcnt = 50,
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Axes & Labels
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Axes_Labels.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Axes & labels',
colourcut = seq(0, 1, length = 11),
maxcnt = 50,
# Customize Axes and labels
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Aspect Ratio
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Aspect_Ratio.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Aspect ratio',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
colourcut = seq(0, 1, length = 11),
maxcnt = 50,
# Set the aspect ratio to control plot dimensions
aspect = 2,
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Colour scheme
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Colour_Change.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Colour change',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
aspect = 1,
colourcut = seq(0, 1, length = 11),
maxcnt = 50,
# Specify colour scheme
colour.scheme = colorRampPalette(c('dodgerblue','paleturquoise','chartreuse','yellow',
'orange','red')),
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Bin sizes
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Bin_Sizes.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Bin sizes',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
aspect = 1,
colour.scheme = colorRampPalette(c('dodgerblue','paleturquoise','chartreuse', 'yellow',
'orange','red')),
# Specify bin sizes
colourcut = seq(0,1,length = 6),
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Correlation Key
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Correlation.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Correlation',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
aspect = 1,
colourcut = seq(0, 1, length = 11),
maxcnt = 50,
# Correlation Key
legend = list(
inside = list(
fun = draw.key,
args = list(
key = get.corr.key(
x = hexbin.data$x,
y = hexbin.data$y,
label.items = c('beta1', 'spearman'),
alpha.background = 0
)
),
x = 0.05,
y = 0.95,
corner = c(0,1),
draw = FALSE
)
),
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Grid lines and diagonal
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Gridlines.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Gridlines',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
aspect = 1,
colourcut = seq(0, 1, length = 11),
maxcnt = 50,
# Grid & diagonal
add.grid = TRUE,
add.xyline = TRUE,
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Large range
# Generate some fake data with both very low and very high values
set.seed(12345);
x <- c(rnorm(100000,0,0.1),rnorm(1000,0,0.5),rnorm(1000,0,sd=0.75));
y <- c(rnorm(100000,0,0.1),rnorm(1000,0,0.5),rnorm(1000,0,sd=0.75));
fake.data <- data.frame(
x = x,
y = y,
z = y + x*(x+1)/4
);
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Range.tiff'),
formula = z ~ x,
data = fake.data,
main = 'Range',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
aspect = 1,
# Use colourcut to divide the bins appropriately
colourcut = c(0,0.0002,0.0004,0.0008,0.0016,0.0032,0.0064,0.0128,0.0256,0.0512,0.1024,0.2048,
0.4096,0.8192,1),
# Change the colour scheme
colour.scheme = function(n){BTC(n, beg=1, end=256)},
background.col = 'grey',
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Outliers
# Generate data with upper bound outlier
set.seed(12345);
x <- c(rnorm(1000,0,0),rnorm(4000,0,0.5));
y <- c(rnorm(1000,0,0),rnorm(4000,0,0.5));
fake.data.outlier <- data.frame(
x = x,
y = y,
z = y + x*(x+1)/4
);
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Outlier.tiff'),
formula = z ~ x,
data = fake.data.outlier,
main = 'Outlier',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlab.label = 'Sample 1',
ylab.label = 'Sample 2',
aspect = 1,
# Use colourcut to divide the bins appropriately
colourcut = c(seq(0,0.01, length = 4),seq(0.0125,0.1,length=4), seq(0.125,1,length=4)),
xbins = 15,
mincnt = 0,
# Change the colour scheme
colour.scheme = function(n){BTC(n, beg=1, end=256)},
background.col = 'grey',
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Nature style
create.hexbinplot(
filename = paste0(tempdir(),'/Hexbinplot_Nature_style.tiff'),
formula = y ~ x,
data = hexbin.data,
main = 'Nature style',
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,16),
ylimits = c(0,16),
xat = seq(0,16,2),
yat = seq(0,16,2),
aspect = 1,
colourcut = seq(0, 1, length = 11),
maxcnt = 50,
# Grid & diagonal
add.grid = TRUE,
add.xyline = TRUE,
# 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)),
description = 'Hexbinplot created by BoutrosLab.plotting.general'
);
# Multiplot different groups
set.seed(73);
# Randomly generate groups
groups <- sample(1:2, 10000, replace = TRUE);
create.hexbinplot(
formula = y ~ x | groups,
filename = paste0(tempdir(),'/stratified_hexbinplot.tiff'),
data = simple.data,
description = 'Hexbinplot created by BoutrosLab.plotting.general',
strip.col = 'white',
strip.cex = 0.8,
strip.fontface = 'bold'
);
# }
Run the code above in your browser using DataLab