# [R] levelplot/heatmap question

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Sep 25 17:37:28 CEST 2008

```On 9/24/08, cerman at u.washington.edu <cerman at u.washington.edu> wrote:
> Hello!
>  I have data containing a large number of probabilities (about 60) of
> nonzero coefficients to predict 10 different independent variables (in 10
> different BMA models). i've arranged these probabilities in a matrix like
> so:
>
>   (IV1)    (IV2)    (IV3)  ...
>   p(b0)    p(b0)    p(b0)
>   p(b1)    p(b1)    p(b1)
>   p(b2)    p(b2)    p(b2)
>  ...
>
>
>  where p(b1) for independent variable 1 is p(b1 != 0) (given model
> uncertainty - using the BMA package). i've also set it so that if the
> coefficient is negative, the probability is listed as negative (to be able
> to distinguish between significant positive and negative effects by color).
>
>  i'd like to create a plot which is a 10x60 grid of rectangles, where each
> rectangle is colored according to its probability of being nonzero
> (preferably white would correspond to a zero probability). i've looked into
> levelplot, heatmap, and image, and cant seem to get exactly what im looking
> for.
>
>  heatmap gives me problems in that the output is inconsistent with the data
> - among other things, the first and last rows do not seem to show up (they
> are just white, despite clearly nonzero probabilities).  even if i do not
> use the dendrogram (Rowv and Colv set to NA), i still seem to have an issue
> with a probability in a given row not corresponding to the same color as the
> same probability in a different row.
>
>  levelplot seems to do exactly what i want it to do, except that i cant find
> a way to label the individual columns and rows, which I really need

The matrix method for levelplot uses rownames and column names to
label columns and rows; e.g.,

x = matrix(1:12, 3, 4)
rownames(x) = letters[1:3]
colnames(x) = LETTERS[1:4]
levelplot(x)

We need more details to figure out why that doesn't work for you.

-Deepayan

```