How to make a color grid in R?

Suppose I have a matrix object in R with values:

aa <- matrix(c(0,4,1,10,3,2,1,6,0), ncol=3) 

And I want to make a figure similar to a figure with this scale.

Can someone help me with a function that can help me make this type of shape in R? or the name of this type of color grid with graphic art?

How can I do this in R?

+6
source share
2 answers

Take a look at the image function. For scale, you probably need the colorscale function in the plotrix package. There are other functions that can also be used for these types of graphs: rasterImage , levelplot in the lattice package, etc. You can even create it from scratch using several calls to rect and other functions if you want to complete the control. But image is probably the fastest / easiest of what you display.

+7
source

Or you can use the raster package.

 library(raster) r <- raster(xmn = 0, xmx = 3, ymn = 0, ymx = 3, nrows = 3, ncols = 3) r[] <- 1:9 plot(r) 

enter image description here

+3
source

Source: https://habr.com/ru/post/923086/