image function in R -


i'm trying little bit complicated beginner in programming. have matrix 16x16 , want plot values heatmap using image() in r. how can plot "0" (zeros) in blue when sum (row index + column index) <= 15? possible?

example matrix:

x <-  c(3045, 893, 692, 830, 617, 155, 246, 657, 105, 60, 18, 7, 7, 4, 2, 11234,  2985, 2242, 2471, 1575, 366, 503, 1283, 170, 79, 32, 6, 4, 1, 3, 19475, 4756,  3233, 3251, 1810, 409, 575, 1210, 139, 41, 11, 4, 2, 0, 0, 20830, 4739, 2990,  2531, 1346, 298, 325, 612, 60, 17, 1, 0, 1, 0, 0, 15304, 3196, 1885, 1440, 610,  117, 115, 185, 14, 2, 0, 0, 0, 0, 0, 8026, 1535, 806, 539, 223, 33, 37, 39, 0,  0, 0, 0, 0, 0, 0, 3300, 562, 286, 141, 45, 14, 5, 12, 0, 0, 0, 0, 0, 0, 0, 1067,  160, 65, 40, 14, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 277, 47, 6, 2, 1, 0, 1, 0, 0, 0,  0, 0, 0, 0, 0, 72, 6, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 5, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)  xmat <- matrix(x, ncol = 12) xmat <- cbind(xmat, rep(0,16), rep(0,16), rep(0,16), rep(0,16)) xmat <- rbind(xmat, rep(0,16)) dimnames(xmat) = list(0:15, 0:15) xmat 

thanks! vitor

plot cases meeting criteria blue.

xmat.new <- xmat xmat.new[!((row(xmat) + col(xmat) <= 15) & xmat==0)] <- na image(xmat.new,col="blue") 

plot cases not meeting criteria normal. notice add=true

xmat.new <- xmat xmat.new[((row(xmat) + col(xmat) <= 15) & xmat==0)] <- na image(xmat.new,add=true) 

result:

enter image description here

edited include @marek's suggestion simplify statements.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -