mat2cols | R Documentation |
Converts a matrix to a hex colour code representation for plotting using plot_cols
. Used internally by plot.Results_IMIFA
for plotting posterior mean loadings heatmaps.
mat2cols(mat, cols = NULL, compare = FALSE, byrank = FALSE, breaks = NULL, na.col = "#808080FF", transparency = 1, ...)
mat |
Either a matrix or, when |
cols |
The colour palette to be used. The default palette uses |
compare |
Logical switch used when desiring comparable colour representations (usually for comparable heat maps) across multiple matrices. Ensures plots will be calibrated to a common colour scale so that, for instance, the colour on the heat map of an entry valued at 0.7 in Matrix A corresponds exactly to the colour of a similar value in Matrix B. When |
byrank |
Logical indicating whether to convert the matrix itself or the sample ranks of the values therein. Defaults to |
breaks |
Number of gradations in colour to use. Defaults to |
na.col |
Colour to be used to represent missing data. Will be checked for validity by |
transparency |
A factor in [0, 1] modifying the opacity for overplotted lines. Defaults to 1 (i.e. no transparency). Only relevant when |
... |
Catches unused arguments. |
A matrix of hex colour code representations, or a list of such matrices when compare
is TRUE
.
plot_cols
, heat_legend
, is.cols
, cut
# 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)) # Use plot_cols() to visualise the colours matrix par(mar=c(5.1, 4.1, 4.1, 3.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 <- cbind(matrix(rnorm(100, sd=c(4,2)), nr=50, nc=2, byrow=TRUE), 0.1) mat2 <- cbind(matrix(rnorm(150, sd=c(7,5,3)), nr=50, nc=3, byrow=TRUE), 0.1) mat3 <- cbind(matrix(rnorm(50, sd=1), nr=50, nc=1, byrow=TRUE), 0.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(mat1), cols=cols); box(lwd=2) plot_cols(mat2cols(mat2, cols=cols)); heat_legend(range(mat2), cols=cols); box(lwd=2) plot_cols(mat2cols(mat3, cols=cols)); heat_legend(range(mat3), cols=cols); box(lwd=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.