# NOT RUN {
# }
# NOT RUN {
# create temp data
set.seed(1234567890);
x <- outer(-5:5, -5:5, '*') + matrix(nrow = 11, ncol = 11, data = runif(11 * 11));
colnames(x) <- paste('col', 1:11, sep = '-');
rownames(x) <- paste('row', 1:11, sep = '-');
# set covariates
covariate.colours1 <- x[,1]
covariate.colours1[covariate.colours1 >= 0] <- default.colours(3)[1];
covariate.colours1[covariate.colours1 != default.colours(3)[1]] <- default.colours(3)[2];
covariate.colours2 <- x[,1]
covariate.colours2[covariate.colours2 >= 0] <- default.colours(3)[2];
covariate.colours2[covariate.colours2 != default.colours(3)[2]] <- default.colours(3)[3];
# create an object to draw the covariates from
covariates1 <- list(
rect = list(
col = 'black',
fill = covariate.colours1,
lwd = 1.5
),
rect = list(
col = 'black',
fill = covariate.colours2,
lwd = 1.5
)
);
# create a covariates grob using a simple incremental ordering and default behaviour
covariates.grob1 <- covariates.grob(
covariates = covariates1,
ord = c(1:ncol(x)),
side = 'right'
);
tiff(
file.path(tempdir(),'covariates_grob1.tiff'),
type = 'cairo',
width = 6,
height = 6,
units = 'in',
res = 1000,
compression = 'lzw'
);
grid.draw(covariates.grob1);
dev.off();
# create a dendrogram for x
cov.dendrogram <- BoutrosLab.plotting.general::create.dendrogram(
x = x,
clustering.method = 'average'
);
covariates2 <-list(
rect = list(
col = 'black',
fill = covariate.colours2,
lwd = 1.5
)
);
# create a covariates grob using the dendrogram ordering and double the default size
covariates.grob2 <- covariates.grob(
covariates = covariates2,
ord = order.dendrogram(cov.dendrogram),
side = 'top',
size = 2
);
tiff(
file.path(tempdir(),'covariates_grob2.tiff'),
type = 'cairo',
width = 6,
height = 6,
units = 'in',
res = 1000,
compression = 'lzw'
);
grid.draw(covariates.grob2);
dev.off();
# add a border of a different colour
covariates.grob3 <- covariates.grob(
covariates = covariates1,
ord = c(1:ncol(x)),
side = 'right',
grid.border = list(col = 'red', lwd = 1.5)
);
tiff(
file.path(tempdir(),'covariates_grob3.tiff'),
type = 'cairo',
width = 6,
height = 6,
units = 'in',
res = 1000,
compression = 'lzw'
);
grid.draw(covariates.grob3);
dev.off();
# create covariates with transparent rectangle borders
covariates3 <- list(
rect = list(
col = 'transparent',
fill = covariate.colours1,
lwd = 1.5
),
rect = list(
col = 'transparent',
fill = covariate.colours2,
lwd = 1.5
)
);
# add column grid lines and a border with default gpar settings
covariates.grob4 <- covariates.grob(
covariates = covariates3,
ord = c(1:nrow(x)),
side = 'top',
grid.col = list(col = 'black', lty = 3),
grid.border = list()
);
tiff(
file.path(tempdir(),'covariates_grob4.tiff'),
type = 'cairo',
width = 6,
height = 6,
units = 'in',
res = 1000,
compression = 'lzw'
);
grid.draw(covariates.grob4);
dev.off();
# draw a subset of row/column lines
covariates.grob5 <- covariates.grob(
covariates = covariates3,
ord = order.dendrogram(cov.dendrogram),
side = 'right',
grid.row = list(lineend = 'butt', lwd = 2),
row.lines = 6,
reorder.grid.index = FALSE, # note: this is already set by default
grid.col = list(lty = 2),
col.lines = c(0,1)
);
tiff(
file.path(tempdir(),'covariates_grob5.tiff'),
type = 'cairo',
width = 6,
height = 6,
units = 'in',
res = 1000,
compression = 'lzw'
);
grid.draw(covariates.grob5);
dev.off();
# }
Run the code above in your browser using DataCamp Workspace