Converting a Number Matrix to a Color Matrix in R -


i have following 4x4 number matrix containing numbers 0-4:

0  1  0  3 3  2  1  4 4  1  0  2 3  3  0  1 

i understand how convert number matrices color matrices using chosen colors , specific square dimensions (length x width) using r. clear, i'm defining color matrix figure using colored squares represent specific values in matrix orientation. example 4x4 program follows:

enter image description here

i have assign color codes numbers, example:

0 = ffffff 1 = 99ff66 2 = 66ff33 3 = 33cc00 4 = 009900 

but don't know begin putting together. imagine have specify dimensions color squares well.

my goal able import data frame r 10 numerical values , create these color charts matrices large 20x20.

here's do:

d<-read.table(text=" 0  1  0  3 3  2  1  4 4  1  0  2 3  3  0  1")  cols <- c( '0' = "#ffffff", '1' = "#99ff66", '2' = "#66ff33", '3' = "#33cc00", '4' = "#009900" ) # names aren't necessary here.  image(1:nrow(d), 1:ncol(d), as.matrix(d), col=cols) 

enter image description here

if you'd prefer orientation different, can rotate matrix:

image(1:nrow(d), 1:ncol(d), t(apply(d, 2, rev)), col=cols) 

to rid of text , borders, might try:

image(1:nrow(d), 1:ncol(d), as.matrix(d), col=cols,    xaxt="n", yaxt="n", bty="n", xlab="", ylab="") 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -