# NOT RUN {
# }
# NOT RUN {
set.seed(12345);
simple.data <- data.frame(
x <- rnorm(1000),
y <- rep('A',1000)
);
create.boxplot(
filename = paste0(tempdir(), '/Boxplot_Simple.tiff'),
formula = y ~ x,
data = simple.data,
main = 'Simple',
description = 'Boxplot created by BoutrosLab.plotting.general'
);
# add stripplot behind boxplot
create.boxplot(
filename = paste0(tempdir(), '/Boxplot_with_Stripplot.tiff'),
formula = y ~ x,
data = simple.data,
main = 'With Stripplot',
add.stripplot = TRUE,
description = 'Boxplot created by BoutrosLab.plotting.general'
);
# 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))
);
# Minimal Input
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Minimal_Input.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'Minimal input',
description = 'Boxplot created by BoutrosLab.plotting.general'
);
# Minimal Input
create.boxplot(
filename = paste0(tempdir(), '/Boxplot_Disable_Factor_Sorting_Input.tiff'),
formula = y ~ x,
data = reformatted.data,
main = 'No Factor Sorting',
disable.factor.sorting = TRUE,
description = 'Boxplot created by BoutrosLab.plotting.general'
);
# Axes and labels
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Axes_Labels.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'
);
# Sorting
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Sorted.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'
);
# Colour change
sex.colour <- recode.vector(
patient$sex,
list(
dodgerblue = 'male',
pink = 'female'
)
);
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Colour_Change.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'
);
# Legend
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Legend.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'
);
# Orientation
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Orientation.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'
);
# Background rectangle
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_BG_Rect.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'
);
# Line
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Line.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'
);
# Panel Organization
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Panels.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'
);
# Nature format
create.boxplot(
filename = paste0(tempdir(),'/Boxplot_Nature_style.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))
);
# Sorting by mean and multiple filenames
create.boxplot(
filename = c(paste0(tempdir(),'/Boxplot_Sorted1.tiff'),
paste0(tempdir(),'/Boxplot_Sorted2.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'
);
# 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 = paste0(tempdir(),'/boxplot_with_text.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)
)
);
# }
Run the code above in your browser using DataLab