Can any body suggest a function to plot heat map for upper or lower triangular matrix in R
the upper triangular of a matrix is the top right triangle, in this case we are masking out the upper triangle of the matrix and just showing the lower triangle part of it. This is because a correlation matrix is symmetric.
Input : mat[4][4] = {{1, 0, 0, 0}, {1, 4, 0, 0}, {4, 6, 2, 0}, {0, 4, 7, 6}}; Output : Matrix is in lower triangular form. Input : mat[4][4] = {{1, 0, 0, 0}, {4, 3, 0, 1}, {7, 9, 2, 0}, {8, 5, 3, 6}}; Output : Matrix is not in lower triangular form.
The most basic way to do something like this would be using ?image
as follows:
M <- matrix(runif(100),10,10)
M[lower.tri(M)] <- NA
image(1:10,1:10,M)
which would result in something like this:
You could also investigate the functions ?heatmap
or in the gplots
package ?heatmap.2
. Doing this using ggplot2
using geom_tile
is a little different but you can find some examples to walk you through the process here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With