[R] Plotting a Trivial Matrix
baptiste auguie
baptiste.auguie at googlemail.com
Fri Feb 26 10:12:39 CET 2010
Hi,
A minimalist example using Grid graphics,
library(RGraphics)
bwImage <- function(m, cols=c("white", "black"),
draw=TRUE, gp=gpar()){
g <- imageGrob(nrow(m), ncol(m),
cols=cols[m+1], gp=gp)
if(draw)
grid.draw(g)
return(g)
}
m <- matrix(rnorm(200) > 0, ncol=20)
bwImage(m)
HTH,
baptiste
On 26 February 2010 09:29, Lorenzo Isella <lorenzo.isella at gmail.com> wrote:
> Dear All,
> Consider a matrix (N x N) where each entry is either zero or one (can
> hardly get any simpler).
> Now, I would like to plot it as a 'chessboard' where every matrix entry
> is a black (1) or white (0) square.
> Whatever tool I use to plot it, it should not try to interpolate the
> data at all.
> I found some online references
> http://www.phaget4.org/R/image_matrix.html
> but probably I can resort to something much simpler.
> Can anyone provide me with a simple example I can modify later on?
> Many thanks
>
> Lorenzo
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
____________________
Baptiste Auguié
Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain
tel: +34 9868 18617
http://webs.uvigo.es/coloides
More information about the R-help
mailing list