set.seed(12345);
simple.data <- data.frame(
x = rnorm(1000),
y = rep('A',1000)
);
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Simple', fileext = '.tiff'),
formula = y ~ x,
data = simple.data,
main = 'Simple',
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 50
);
# add stripplot behind boxplot
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_with_Stripplot', fileext = '.tiff'),
formula = y ~ x,
data = simple.data,
main = 'With Stripplot',
add.stripplot = TRUE,
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 50
);
# Multi-coloured stripplot
strip.data <- data.frame(
score = c(rnorm(30, 15, 3), rnorm(50, 20, 4)),
sex = sample(c('male', 'female'), 80, replace = TRUE),
gene = sample(c('a', 'b'), 80, replace = TRUE)
);
create.boxplot(
filename = NULL,
formula = score ~ sex | gene,
data = strip.data,
main = 'Multi-Coloured Stripplot',
add.stripplot = TRUE,
points.col = c('pink', 'dodgerblue'),
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# format data
reformatted.data <- data.frame(
x = as.vector(t(microarray[1:10,1:58])),
y = as.factor(rep(rownames(microarray[1:10,1:58]),each = 58)),
z = sample(1:10, 580, replace = TRUE)
);
# Minimal Input
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Minimal_Input', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Minimal input',
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 50
);
# Minimal Input
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Disable_Factor_Sorting_Input', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'No Factor Sorting',
disable.factor.sorting = TRUE,
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 50
);
# Axes and labels
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Axes_Labels', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Axes & labels',
# Adjusting axes size
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
# Adding y-axis label
ylab.label = 'Gene',
# setting axes limits
xlimits = c(0,13),
xat = seq(0,12,2),
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# \donttest{
# Sorting
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Sorted', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Sorting',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
# Reordered by median
sample.order = 'increasing',
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# Colour change
sex.colour <- as.character(patient$sex);
sex.colour[sex.colour == 'male'] <- 'dodgerblue';
sex.colour[sex.colour == 'female'] <- 'pink';
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Colour_Change', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Colour change',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
# Colour change
col = sex.colour,
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# Remove y-axis labels
create.boxplot(
formula = y ~ x,
data = reformatted.data,
main = 'Remove y-axis labels',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
yaxis.lab = NULL, # Remove labels with NULL
# Colour change
col = sex.colour,
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# Log Scaled Axis
log.data <- data.frame(
x = 10 ** rnorm(1000, 5, 2),
y = rep('A',1000)
);
create.boxplot(
formula = x ~ y,
data = log.data,
# Log base 10 scale y axis
yat = 'auto.log',
main = 'Log Scale',
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# Legend
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Legend', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Legend',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
col = sex.colour,
# legend
legend = list(
inside = list(
fun = draw.key,
args = list(
key = list(
points = list(
col = 'black',
pch = 22,
cex = 1.5,
fill = c('dodgerblue','pink')
),
text = list(
lab = c('male','female')
),
cex = 1
)
),
x = 0.03,
y = 0.97,
corner = c(0,1),
draw = FALSE
)
),
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 100
);
# Orientation
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Orientation', fileext = '.tiff'),
# switch the order
formula = x ~ y,
data = reformatted.data,
main = 'Orientation',
xaxis.cex = 1,
yaxis.cex = 1,
# adjust the axes
ylimits = c(0,13),
yat = seq(0,12,2),
# rotate the labels
xaxis.rot = 90,
xlab.label = 'Gene',
xlab.cex = 1.5,
col = sex.colour,
# legend
legend = list(
inside = list(
fun = draw.key,
args = list(
key = list(
points = list(
col = 'black',
pch = 22,
cex = 1.5,
fill = c('dodgerblue','pink')
),
text = list(
lab = c('male','female')
),
cex = 1
)
),
x = 0.23,
y = 0.97,
corner = c(0,1),
draw = FALSE
)
),
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 200
);
# Background rectangle
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_BG_Rect', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Bg rectangle',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
# draw rectangle
add.rectangle = TRUE,
xleft.rectangle = 0,
xright.rectangle = 13,
ybottom.rectangle = seq(0.5, 8.5, 2),
ytop.rectangle = seq(1.5, 9.5, 2),
col.rectangle = 'grey',
alpha.rectangle = 0.5,
col = sex.colour,
# legend
legend = list(
inside = list(
fun = draw.key,
args = list(
key = list(
points = list(
col = 'black',
pch = 22,
cex = 1.5,
fill = c('dodgerblue','pink')
),
text = list(
lab = c('male','female')
),
cex = 1
)
),
x = 0.03,
y = 0.97,
corner = c(0,1),
draw = FALSE
)
),
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 200
);
# Line
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Line', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Line',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
# draw line
line.func = function(x){c(0.5, 10.5)},
line.from = 11,
line.to = 11,
line.col = 'grey',
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 200
);
# Panel Organization
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Panels_numeric_conditioning', fileext = '.tiff'),
formula = ~ x | z,
data = reformatted.data,
main = 'Panels',
xaxis.cex = 1,
yaxis.cex = 1,
xlimits = c(0,13),
xat = seq(0,12,2),
# Setting up the layout
layout = c(2,5),
x.relation = 'free',
x.spacing = 1,
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 200
);
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Panels_factor_conditioning', fileext = '.tiff'),
formula = ~ x | y,
data = reformatted.data,
main = 'Panels',
xaxis.cex = 1,
yaxis.cex = 1,
xlimits = c(0,13),
xat = seq(0,12,2),
# Setting up the layout
layout = c(2,5),
x.relation = 'free',
x.spacing = 1,
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 200
);
# Nature format
create.boxplot(
# filename = tempfile(pattern = 'Boxplot_Nature_style', fileext = '.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Nature style',
xaxis.cex = 1,
yaxis.cex = 1,
# 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)),
resolution = 1200
);
# Sorting by mean and multiple filenames
create.boxplot(
filename = c(
tempfile(pattern = 'Boxplot_Sorted1', fileext = '.tiff'),
tempfile(pattern = 'Boxplot_Sorted2', fileext = '.tiff')
),
formula = y ~ x,
data = reformatted.data,
main = 'Sorting',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
ylab.label = 'Gene',
xlimits = c(0,13),
xat = seq(0,12,2),
# Reordered by median
sample.order = 'increasing',
order.by = 'mean',
description = 'Boxplot created by BoutrosLab.plotting.general',
resolution = 200
);
# Adding text to plot
# Generate normally distributed variables with two different means
set.seed(779);
groupA <- rnorm(n = 100, mean = 10, sd = 2);
groupB <- rnorm(n = 134, mean = 10.5, sd = 2);
# Create data frame for plotting
to.plot <- data.frame(
y = rep(
c('1', '2'),
times = c(100, 134)
),
x = c(groupA, groupB)
);
# Get difference between means
diff.mean <- round(mean(groupB) - mean(groupA), 2);
# Plot and display difference
create.boxplot(
formula = x ~ y,
# filename = tempfile(pattern = 'boxplot_with_text', fileext = '.tiff'),
data = to.plot,
add.stripplot = TRUE,
add.text = TRUE,
text.labels = bquote(mu[B] - mu[A] == .(diff.mean)),
text.x = 2.1,
text.y = 15.3,
text.col = 'black',
text.cex = 1.5,
text.fontface = 'bold',
ylimits = c(
min(to.plot$x) - abs(min(to.plot$x) * 0.1),
max(to.plot$x) + abs(max(to.plot$x) * 0.1)
),
resolution = 200
);
# }
Run the code above in your browser using DataLab