# NOT RUN {
# }
# NOT RUN {
set.seed(12345);
simple.data <- data.frame(
x = c(rep(rnorm(50),5)),
y = as.factor(sample(LETTERS[1:5],250,TRUE))
);
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Simple.tiff'),
formula = x ~ y,
data = simple.data
);
# load real datasets
violin.data <- data.frame(
values = c(t(microarray[1:10, 1:58])),
genes = rep(rownames(microarray)[1:10], each = 58),
sex = patient$sex
);
# Minimal input
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Minimal_Input.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Minimal input',
xaxis.rot = 90,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Axes & Labels
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Axes_Labels.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Axes & labels',
xaxis.rot = 90,
# Adjusting axes
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 13),
yat = seq(0, 12, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Range
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Range.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Range',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
# adjusted y-axis limits
ylimits = c(0, 11),
yat = seq(0, 10, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
# Specify range
start = 1,
end = 10,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Scaling
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Scale.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Scale',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 13),
yat = seq(0, 12, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
# Scale
scale = TRUE,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Extra points
median.points <- unlist(tapply(violin.data$values, violin.data$genes, median));
top.points <- unlist(tapply(violin.data$values, violin.data$genes, quantile, 0.90));
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Points.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Extra points',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 13),
yat = seq(0, 12, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
# Adding median and 90th percentile
extra.points = list(median.points, top.points),
extra.points.pch = 21,
extra.points.col = c('white','grey'),
extra.points.cex = 0.5,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Colours
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Colour.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Colour',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 13),
yat = seq(0, 12, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
extra.points = list(median.points, top.points),
extra.points.pch = 21,
extra.points.col = c('white','grey'),
extra.points.cex = 0.5,
# Colour
col = 'dodgerblue',
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Custom labels
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Custom_Labels.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Custom labels',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 16),
yat = c(0,1,2,4,8,16),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
extra.points = list(median.points, top.points),
extra.points.pch = 21,
extra.points.col = c('white','grey'),
extra.points.cex = 0.5,
col = 'dodgerblue',
# customizing labels
yaxis.lab = c(
0,
expression(paste('2'^'0')),
expression(paste('2'^'1')),
expression(paste('2'^'2')),
expression(paste('2'^'4')),
expression(paste('2'^'5'))
),
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Orientation
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Orientation.tiff'),
# switch formula
formula = genes ~ values,
data = violin.data,
main = 'Orientation',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
xaxis.fontface = 1,
yaxis.fontface = 1,
ylab.label = 'Gene',
xlab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
extra.points = list(median.points, top.points),
extra.points.pch = 21,
extra.points.col = c('white','grey'),
extra.points.cex = 0.5,
col = 'dodgerblue',
# orientation
plot.horizontal = TRUE,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# background
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Background.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Background rectangle',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 13),
yat = seq(0, 12, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.label = 'Gene',
ylab.label = 'Change in expression',
xlab.cex = 1.5,
ylab.cex = 1.5,
extra.points = list(median.points, top.points),
extra.points.pch = 21,
extra.points.col = c('white','grey'),
extra.points.cex = 0.5,
col = 'dodgerblue',
# background
add.rectangle = TRUE,
xleft.rectangle = seq(0.5, 8.5, 2),
ybottom.rectangle = 0,
xright.rectangle = seq(1.5, 9.5, 2),
ytop.rectangle = 13,
col.rectangle = 'grey',
alpha.rectangle = 0.5,
description = 'Violinplot created by BoutrosLab.plotting.general'
);
# Nature style
create.violinplot(
filename = paste0(tempdir(),'/Violinplot_Nature_style.tiff'),
formula = values ~ genes,
data = violin.data,
main = 'Nature style',
xaxis.rot = 90,
xaxis.cex = 1,
yaxis.cex = 1,
ylimits = c(0, 13),
yat = seq(0, 12, 2),
xaxis.fontface = 1,
yaxis.fontface = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
col = 'dodgerblue',
add.rectangle = TRUE,
xleft.rectangle = seq(0.5, 8.5, 2),
ybottom.rectangle = 0,
xright.rectangle = seq(1.5, 9.5, 2),
ytop.rectangle = 13,
col.rectangle = 'grey',
alpha.rectangle = 0.5,
# 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 = 'Violinplot created by BoutrosLab.plotting.general'
);
# }
Run the code above in your browser using DataLab