draw.hexagon <- function (pos, Col="white", Border=1, BG="white", Scale=1, main="") { # The coordinates of the hexagon hex <- matrix(c(0, 0.5, 0.5, 0, -0.5, -0.5, 0, 1.732, 0.866, -0.866, -1.732, -0.866, 0.866, 1.732), 7, 2) old.par <- par(pty = "s", bg=BG, bty="n", xaxt="n", yaxt="n", mar=c(1,1,1,1)) x.r <- range(pos[,1])+c(-2, 2) y.r <- range(pos[,2])*3+c(-2, 2) plot(0, 0, xlim=x.r, ylim=y.r, type="n", xlab="", ylab="", main=main) a <- 3 # a scaling factor if (length(Scale) != dim(pos)[1]) { scale <- rep(1, dim(pos)[1]) } else { scale <- Scale } if (Border == 0) { for (i in 1:dim(pos)[1]) { polygon(pos[i,1]+scale[i]*hex[,1], a*pos[i,2]+scale[i]*hex[,2], col=Col[i], border=Col[i]) } } else { for (i in 1:dim(pos)[1]) { polygon(pos[i,1]+scale[i]*hex[,1], a*pos[i,2]+scale[i]*hex[,2], col=Col[i], border=Border) } } par(old.par) } # draw.hexagon(cbind(0,0)) # draw.hexagon(Coords[1:5,], Scale=(1:5)/3) # draw.hexagon(Coords, Col="white") update.hexagon <- function (pos, Col="white", Border=1,Scale=1) { hex <- matrix(c(0, 0.5, 0.5, 0, -0.5, -0.5, 0, 1.732, 0.866, -0.866, -1.732, -0.866, 0.866, 1.732), 7, 2) oldpar <- par(pty = "s", bg="gray", bty="n", xaxt="n", yaxt="n", mar=c(1,1,1,1)) x.r <- range(pos[,1])+c(-2, 2) y.r <- range(pos[,2])*3+c(-2, 2) a <- 3 if (length(Scale) != dim(pos)[1]) { scale <- rep(1, dim(pos)[1]) } else { scale <- Scale } if (Border == 0) { for (i in 1:dim(pos)[1]) { polygon(pos[i,1]+scale[i]*hex[,1], a*pos[i,2]+scale[i]*hex[,2], col=Col[i], border=Col[i]) } } else { for (i in 1:dim(pos)[1]) { polygon(pos[i,1]+scale[i]*hex[,1], a*pos[i,2]+scale[i]*hex[,2], col=Col[i], border=Border) } } par(oldpar) } draw.hexagon.3count <- function (pos, Hits, Col="white", BG="white", Scale=1, main="") { # The coordinates of the hexagon hex <- matrix(c(0, 0.5, 0.5, 0, -0.5, -0.5, 0, 1.732, 0.866, -0.866, -1.732, -0.866, 0.866, 1.732), 7, 2) old.par <- par(pty = "s", bg=BG, bty="n", xaxt="n", yaxt="n", mar=c(1,1,1,1)) x.r <- range(pos[,1])+c(-2, 2) y.r <- range(pos[,2])*3+c(-2, 2) plot(0, 0, xlim=x.r, ylim=y.r, type="n", xlab="", ylab="", main=main) a <- 3 # a scaling factor if (length(Scale) != dim(pos)[1]) { scale <- rep(1, dim(pos)[1]) } else { scale <- Scale } for (i in 1:dim(pos)[1]) { polygon(pos[i,1]+scale[i]*hex[,1], a*pos[i,2]+scale[i]*hex[,2], col=Col[i], border=1) if (Hits[i,1] != 0) { text(pos[i,1],a*pos[i,2]-.7, paste("1: ", Hits[i,1]), col="red") } if (Hits[i,2] != 0) { text(pos[i,1],a*pos[i,2], paste("2: ",Hits[i,2]), col="green") } if (Hits[i,3] != 0) { text(pos[i,1],a*pos[i,2]+.7, paste("3: ",Hits[i,3]), col="blue") } } par(old.par) }