Skip to content

Visualize Sparse Matrix.

1 message · FRANCISCO XAVIER SUMBA TORAL

#
Hi, 

Thanks for your help.

I used the SparseM package http://www.econ.uiuc.edu/~roger/research/sparse/SparseM.pdf <http://www.econ.uiuc.edu/~roger/research/sparse/SparseM.pdf>
First of all, I create a class for sparse matrices stored in Compressed Sparse Row (CSR) with as.matrix.csr(matrix).
After that, I plot the non-zero entries of a matrix of class matrix.csr with image(m.csr)


This is my code:

library(SparseM)
data <- read.csv(pathCSV, header = FALSE, sep = ",")
numcol <- ncol(data)
dMatrix <- matrix(unlist(data), ncol = numcol, byrow = TRUE)
dMatrix.csr <- as.matrix.csr(dMatrix)
image(dMatrix.csr, col=c("white","blue"))

After clustering, I will have the same matrix but each row (vector) has a tag to represent a cluster id. So, how could I plot my matrix to show a different color for cluster id?

This is an example of my results:

213	0	0 	0 	0.213	0.3423  
345	0	0 	0.32 0		0  
84	0	0.4 	0 	0.54		0  
84	0.86	0 	0 	0		0  
213	0	0.98 0 	0		0.45  
345	0	0.57 0 	0		0.4  

Cheers.