Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting a heat map for an upper or lower triangular matrix

Can any body suggest a function to plot heat map for upper or lower triangular matrix in R

like image 849
nit Avatar asked Jul 30 '11 14:07

nit


People also ask

What is upper triangular correlation matrix?

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.

How do you find the lower triangular matrix in python?

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.


1 Answers

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:

enter image description here

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.

like image 154
joran Avatar answered Sep 16 '22 17:09

joran