Plotting a heat map for an upper or lower triangular matrix

nit picture nit · Jul 30, 2011 · Viewed 7.9k times · Source

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

Answer

joran picture joran · Jul 30, 2011

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.