[R] Visualize Sparse Matrix.

Jim Lemon drjimlemon at gmail.com
Sat Jun 11 00:56:00 CEST 2016


Hi Francisco,
Your example plot shows me what you want to do (I think). I'm guessing that
you want to display the values in your matrix that are NOT zero or NA,
either colored in some way, or just in one color as the example. The
following example shows how to do both of these:

# wtmat<-matrix(rnorm(4602*1817),nrow=4602)
# use a smaller matrix to illustrate the principle
wtmat<-matrix(rnorm(46*18),nrow=46)
# make it "sparse" by taking out all small values
# in your case this may be changing all zero values to NS
wtmat[abs(wtmat)<1]<-NA
library(plotrix)
x11(width=5,height=13)
# display all values in the matrix
# colored as red->white (negative values), white (NA)
# and white->black (positive values)
color2D.matplot(wtmat,c(1,1,0),c(0,1,0),c(0,1,0),border=FALSE)
# now do a plot just showing values that are not NA
color2D.matplot(abs(wtmat),extremes=c(4,4),border=FALSE)

My original example also looked "dirty", albeit colorful, because there
were so many rectangles on it. With a PDF plot about 500mm high you can see
the individual rectangles in a matrix plot of your original dimensions.

Jim


On Sat, Jun 11, 2016 at 3:29 AM, FRANCISCO XAVIER SUMBA TORAL <
xavier.sumba93 at ucuenca.ec> wrote:

> Hi Jim,
>
> Thanks for your answer.
>
> I try your code example, but it is basically the same that I had it. I
> want to visualise my matrix something like this image:
>
> snipped
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list