Visualize Sparse Matrix.
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.
On Jun 10, 2016, at 18:51, Amos Elberg <amos.elberg at gmail.com> wrote: Sparse matrix visualization is a feature of my largeVis package: https://github.com/elbamos/largeVis/tree/0.1.6 <https://github.com/elbamos/largeVis/tree/0.1.6> On Thu, Jun 9, 2016 at 6:27 PM, FRANCISCO XAVIER SUMBA TORAL <xavier.sumba93 at ucuenca.ec <mailto:xavier.sumba93 at ucuenca.ec>> wrote: Hi, First of all, sorry for my question it could be so basic for a common user in R, but I am starting with this new environment. I have done a clustering job and I would like to visualize my vectors. I have a matrix of TF-IDF weights of 4602 x 1817. I store the values in a CSV file. How can I visualize my vectors in a 2D-space? After that, I execute a clustering algorithm and I got a label for each cluster. How can I visualize my vectors resulting base on a color or figure for each cluster? This is the code that I am having trying to accomplish my graphs: data <- read.csv(pathFile,header = FALSE, sep = ",?) dMatrix <- matrix(unlist(data), ncol = 4602, byrow = TRUE) # Use a matrix to use melt. # Graph my data ggplot(melt(dMatrix), aes(Var1,Var2, fill=value)) + geom_raster() + scale_fill_gradient2(low='red', high=?black', mid=?white') + theme_bw() + xlab("x1") + ylab("x2") Cheers. [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org <mailto:R-help at r-project.org> mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.r-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.