How to create an image of matrix of pixels in R?


A matrix can be converted into a pixel’s image of matrix. It is defined as the area of the matrix which contains pixels with equal or different sizes of left, right, bottom and upper.

We can create this by using image function and its argument useRaster with the matrix data.

Example

 Live Demo

> M<-matrix(rnorm(100,1.5),nrow=10)
> par(mar=c(5,5,5,5))
> image(M,useRaster=TRUE,axes=FALSE)

Output

> par(mar=c(10,10,10,10))
> image(M,useRaster=TRUE,axes=FALSE)

Output

> par(mar=c(2,2,2,2))
> image(M,useRaster=TRUE,axes=FALSE)

Output

Pixel matrix with grey color −

> image(M,axes=FALSE,col=grey(seq(0,1,length=180)))

Output

Updated on: 07-Sep-2020

610 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements