Learn R Programming

berryFunctions (version 1.4)

tableColVal: Table with values with value-dependent colored backgrounds in pdf

Description

Table with numbers and corresponding color in the background of each cell. (heatmap)

Usage

tableColVal(mat, pdffile="table_col_val.pdf", pdf=FALSE, nameswidth=0.3,
namesheight=0.1, palette=rainbow(nrow(mat)*ncol(mat), start=0, end=0.7),
Range=range(mat,finite=TRUE), cex.titles=1, col.titles=1, cex.text=1, 
col.text=1, main="code by\nberry-b@gmx.de", cex.main=1, col.main=1, ...)

Arguments

mat
Matrix with values
pdffile
Name of File to write to. DEFAULT: "table_col_val.pdf"
pdf
Should table be written to pdffile? (Else it will plot in x11). DEFAULT: FALSE
nameswidth
Relative width of row names at the left, as a percentage of plot. DEFAULT: 0.3
namesheight
Relative height of column names at the top. DEFAULT: 0.1
palette
Color palette for the heatmap. DEFAULT: rainbow(nrow(mat)*ncol(mat), start=0, end=0.7)
Range
Range of values mapped linearly to color palette. DEFAULT: range(mat,finite
cex.titles
Size of row and column labels. DEFAULT: 1
col.titles
Color of labels. DEFAULT: 1
cex.text
Size of cell text. DEFAULT: 1
col.text
Color of cell text. DEFAULT: 1
main
Title to be put in upper left cell. DEFAULT: "code by\nberry-b@gmx.de"
cex.main
Title size. DEFAULT: 1
col.main
Title color. DEFAULT: 1
...
Further Arguments passed to pdf

Value

  • None. PDF or plot produced.

See Also

pdf, heatmap

Examples

Run this code
Bsp <- matrix(c(21,23,26,27, 18,24,25,28, 14,17,23,23, 16,19,21,25), ncol=4, byrow=TRUE)
colnames(Bsp) <- paste0("Measure", LETTERS[1:4])
rownames(Bsp) <- paste("prod", 8:11, sep="_")
Bsp

tableColVal(Bsp, pdf=FALSE)
tableColVal(Bsp, pdf=FALSE, nameswidth=0.1) # relative to plot width
tableColVal(Bsp, pdf=FALSE, col.titles=2, cex.text=2, col.main=3)
tableColVal(Bsp, pdf=FALSE, Range=c(10,40))
tableColVal(Bsp, pdf=FALSE, palette=heat.colors(12))
tableColVal(Bsp, pdf=FALSE, palette=c(2,4,7), main="last
comparison")


tableColVal(Bsp)
dev.off()
tableColVal(Bsp, width=12, cex.text=2)  # further arguments to pdf possible.

Bsp2 <- matrix(sample(1:100, 30), ncol=6, byrow=TRUE)
graphics.off(); windows(height=4)
tableColVal(Bsp2, pdf=FALSE)

Run the code above in your browser using DataLab