# NOT RUN {
# Generate a colour matrix using mat2cols()
mat <- matrix(rnorm(100), nrow=10, ncol=10)
mat[2,3] <- NA
cols <- heat.colors(12)[12:1]
matcol <- mat2cols(mat, cols=cols)
matcol
# Use plot_cols() to visualise the colours matrix
par(mar=c(5.1, 4.1, 4.1, 4.1))
plot_cols(matcol)
# Add a legend using heat_legend()
heat_legend(mat, cols=cols); box(lwd=2)
# Try comparing heat maps of multiple matrices
mat1 <- matrix(rnorm(100), nr=50, nc=2)
mat2 <- matrix(rnorm(150), nr=50, nc=3)
mat3 <- matrix(rnorm(50), nr=50, nc=1)
mats <- list(mat1, mat2, mat3)
colmats <- mat2cols(mats, cols=cols, compare=TRUE)
par(mfrow=c(2, 3), mar=c(1, 2, 1, 2))
# Use common palettes (top row)
plot_cols(colmats[[1]]); heat_legend(range(mats), cols=cols); box(lwd=2)
plot_cols(colmats[[2]]); heat_legend(range(mats), cols=cols); box(lwd=2)
plot_cols(colmats[[3]]); heat_legend(range(mats), cols=cols); box(lwd=2)
# Use uncommon palettes (bottom row)
plot_cols(mat2cols(mat1, cols=cols)); heat_legend(range(mats), cols=cols); box(lwd=2)
plot_cols(mat2cols(mat2, cols=cols)); heat_legend(range(mats), cols=cols); box(lwd=2)
plot_cols(mat2cols(mat3, cols=cols)); heat_legend(range(mats), cols=cols); box(lwd=2)
# }
Run the code above in your browser using DataLab