# NOT RUN {
# }
# NOT RUN {
set.seed(12345);
simple.data <- data.frame(
min = runif(10,5,15),
max = runif(10,15,25),
labels = as.factor(LETTERS[1:10])
);
create.segplot(
filename = paste0(tempdir(),'/Segplot_simple.tiff'),
formula = labels ~ min + max,
data = simple.data
);
# load some data
length.of.gene <- apply(microarray[1:10,60:61], 1, diff);
bin.length <- length.of.gene;
bin.length[which(bin.length < 20000)] <- 'A';
bin.length[which(bin.length < 40000)] <- 'B';
bin.length[which(bin.length < 60000)] <- 'C';
segplot.data <- data.frame(
min = apply(microarray[1:10,1:58], 1, min),
max = apply(microarray[1:10,1:58], 1, max),
median = apply(microarray[1:10,1:58], 1, median),
gene = rownames(microarray)[1:10],
# approximating length of gene
length = as.factor(bin.length)
);
# Minimal Input using real data
create.segplot(
filename = paste0(tempdir(),'/Segplot_Minimal_Input.tiff'),
formula = gene ~ min + max,
data = segplot.data,
main = 'Minimal input',
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Axes & Labels
create.segplot(
filename = paste0(tempdir(),'/Segplot_Axes_Labels.tiff'),
formula = gene ~ min + max,
data = segplot.data,
main = 'Axes & labels',
# Formatting axes
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Bands
create.segplot(
filename = paste0(tempdir(),'/Segplot_Bands.tiff'),
formula = gene ~ min + max,
data = segplot.data,
main = 'Bands',
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
# drawing rectangles instead of lines
draw.bands = TRUE,
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Colours
create.segplot(
filename = paste0(tempdir(),'/Segplot_Colours.tiff'),
formula = reorder(gene, median) ~ min + max,
data = segplot.data,
main = 'Colours',
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
draw.bands = FALSE,
# Changing the colours based on a covariate ('level' parameter)
level = segplot.data$length,
col.regions = default.colours(3),
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Median
create.segplot(
filename = paste0(tempdir(),'/Segplot_Median.tiff'),
formula = gene ~ min + max,
data = segplot.data,
main = 'Medians',
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
draw.bands = FALSE,
xat = seq(0, 12, 2),
level = segplot.data$length,
col.regions = default.colours(3),
# Adding center values
centers = segplot.data$median,
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Reorder by center value
create.segplot(
filename = paste0(tempdir(),'/Segplot_Reorder.tiff'),
formula = reorder(gene, median) ~ min + max,
data = segplot.data,
main = 'Reordered',
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
draw.bands = FALSE,
centers = segplot.data$median,
level = segplot.data$length,
col.regions = default.colours(3),
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Legend
create.segplot(
filename = paste0(tempdir(),'/Segplot_Legend.tiff'),
formula = reorder(gene, median) ~ min + max,
data = segplot.data,
main = 'Legend',
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
draw.bands = FALSE,
centers = segplot.data$median,
level = segplot.data$length,
col.regions = default.colours(3),
# Adding legend to explain colours
legend = list(
inside = list(
fun = draw.key,
args = list(
key = list(
points = list(
col = default.colours(3),
pch = 19,
cex = 1
),
text = list(
lab = c('1-20000 bp', '20001-40000 bp','40001-60000 bp')
),
padding.text = 1,
cex = 1
)
),
x = 0.60,
y = 0.15,
corner = c(0,1)
)
),
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Background
create.segplot(
filename = paste0(tempdir(),'/Segplot_Background.tiff'),
formula = reorder(gene, median) ~ min + max,
data = segplot.data,
main = 'Background rectangle',
xlab.label = 'Change in gene expression',
ylab.label = 'Gene',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
draw.bands = FALSE,
centers = segplot.data$median,
level = segplot.data$length,
col.regions = default.colours(3),
# Adding legend to explain colours
legend = list(
inside = list(
fun = draw.key,
args = list(
key = list(
points = list(
col = default.colours(3),
pch = 19,
cex = 1
),
text = list(
lab = c('1-20000 bp', '20001-40000 bp','40001-60000 bp')
),
padding.text = 1,
cex = 1
)
),
x = 0.50,
y = 0.15,
corner = c(0,1)
)
),
# adding background shading
add.rectangle = TRUE,
xleft.rectangle = 0,
ybottom.rectangle = seq(0.5, 8.5, 2),
xright.rectangle = 13,
ytop.rectangle = seq(1.5, 9.5, 2),
col.rectangle = 'grey',
alpha.rectangle = 0.5,
description = 'Segplot created by BoutrosLab.plotting.general'
);
# Nature style
create.segplot(
filename = paste0(tempdir(),'/Segplot_Nature_style.tiff'),
formula = reorder(gene, median) ~ min + max,
data = segplot.data,
main = 'Nature style',
xaxis.cex = 1,
yaxis.cex = 1,
xlab.cex = 1.5,
ylab.cex = 1.5,
xlimits = c(0,13),
xat = seq(0, 12, 2),
draw.bands = FALSE,
centers = segplot.data$median,
level = segplot.data$length,
col.regions = default.colours(3),
legend = list(
inside = list(
fun = draw.key,
args = list(
key = list(
points = list(
col = default.colours(3),
pch = 19,
cex = 1
),
text = list(
lab = c('1-20000 bp', '20001-40000 bp','40001-60000 bp')
),
padding.text = 1,
cex = 1
)
),
x = 0.50,
y = 0.15,
corner = c(0,1)
)
),
add.rectangle = TRUE,
xleft.rectangle = 0,
ybottom.rectangle = seq(0.5, 8.5, 2),
xright.rectangle = 13,
ytop.rectangle = seq(1.5, 9.5, 2),
col.rectangle = 'grey',
alpha.rectangle = 0.5,
# set style to Nature
style = 'Nature',
# demonstrating how to italicize character variables
ylab.label = expression(paste('italicized ', italic('a'))),
# demonstrating how to create en-dashes
xlab.label = expression(paste('en dashs: 1','\u2013', '10'^'\u2013', ''^3)),
description = 'Segplot created by BoutrosLab.plotting.general'
);
# example of bands and lines
create.segplot(
filename = paste0(tempdir(),'/Segplot_BandsAndLines.tiff'),
formula = labels ~ min + max,
data = simple.data,
draw.bands = c(1,3,5,7,9)
);
# }
Run the code above in your browser using DataCamp Workspace