I have big binary matrix (0,1) and I want to visualize it so that every entry of my matrix is one pixel in the plot.
I use the image()
function, but it does not
As the image
plots the counter-clockwise rotation of the input matrix, you have to transpose it and then flip it to be normally plotted:
tb <- t(b)
ftb <- tb[ , ncol(tb):1]
Now you can use custom colors if you don't like the default ones, e.g. 0 is grey and 1 is red. Also using the asp
equal to one makes each pixel of the image rectangular (from @koekenbakker's comment ).
image(x=1:2, y=1:4, ftb, col = c("grey", "red"), asp = 1)
I dnt know about the image() function, but you can do this with EBImage package like this.
a<-list(c(0,1,1,0),c(1,1,0,0))
b<-matrix(unlist(a),ncol=2)
library(EBImage)
x <- as.Image(b)
display(x,method='raster')