-2

I have an n x n symmetric matrix, with values equal to -1, 0, or 1. I plotted the matrix using image(), and levelplot(), giving different colors for -1, and 1 (0 implies no values, hence no color, or white).

However, I could not change the point style (using pch) for either of the two functions, or with heatmap and other options for that matter.

I trying to represent -1, and 1 with different colors, and different point styles (circle, and say, triangle). Something like shown here: http://www.ploscompbiol.org/article/fetchObject.action?uri=info:doi/10.1371/journal.pcbi.1002004.g007&representation=PNG_M

Thank you for your help.

sredemption
  • 145
  • 1
  • 6
  • 1
    Please include some example code, preferably with a [reproducible example](http://stackoverflow.com/q/5963269/1222578) of your data. – Marius Oct 07 '14 at 22:58
  • The data is as [rnso](http://stackoverflow.com/users/3522130/rnso) described, except that the data is in form of a symmetrical matrix. And then I used `levelplot()` from package `lattice`, with different colors for -1, 1, and white for zeros. – sredemption Oct 08 '14 at 18:08

1 Answers1

2

Try:

xx = matrix(sample(-1:1, 16, replace=T), nrow=4)
xx
     [,1] [,2] [,3] [,4]
[1,]    0    1    0    1
[2,]    1   -1    1    1
[3,]    1    1   -1    0
[4,]    0    1    1   -1

dd = data.frame(xx)
dd$id = rownames(dd)
ggplot(melt(dd))+geom_point(aes(x=variable, y=id, color=value, shape=value))

enter image description here

To omit points with 0:

mm = melt(dd)
mm$value[mm$value==0] = NA
ggplot(mm)+geom_point(aes(x=variable, y=id, color=factor(value), shape=factor(value)),size=5)

enter image description here

rnso
  • 23,686
  • 25
  • 112
  • 234
  • Thank you for your response. However, your example does not preserve the order of the original data (matrix). I was able to vertically flip the original matrix (using `apply(xx, 2, rev)`), and then use example code. – sredemption Oct 08 '14 at 18:26
  • I focussed "to represent -1, and 1 with different colors, and different point styles" which was your major problem. – rnso Oct 09 '14 at 01:35