library(grid) # Install this library if you don't have it already. plot.hc <- function(mat){ m <- dim(mat)[1] n <- dim(mat)[2] grid.newpage() rad = .02 xx = function(j) {j/(n+1)} yy = function(i) {(m+1-i)/(m+1)} for(i in 1:m)grid.lines(c(xx(1),xx(n)),c(yy(i),yy(i))) for(j in 1:n)grid.lines(c(xx(j),xx(j)),c(yy(1),yy(m))) for(j in 1:n){ for(i in 1:m){ mycolor <- c('black','green')[1+mat[i,j]] grid.circle(xx(j),yy(i),rad,gp=gpar(fill=mycolor)) } } } set.seed(3) m <- 8 n <- 8 mat <- matrix(rbinom(m*n, 1, .2),m,n) mat plot.hc(mat) # Note: the "mat" you just created does not satisfy the hard-core # constraint; it is just an example to demonstrate the plot.hc function.