Question

I want to create a connect four board based on the tictactoe board I have. However things sound not be matching and I don't have the results quite right. I want to have 6 rows and 7 columns!

par(pty="s") # square plot type
x = rep(1:6, each = 6)
y = rep(1:7, times = 7)
symbols(x, y, squares=rep(1, times=42),
        inches=FALSE, # match squares to axes
        xlim=c(0,7),
        ylim=c(8,0)) # flip y axis to match matrix format
board = matrix(rep("E", times=42), nrow=6, ncol=7)

And I receive this error:

Error in xy.coords(x, y, xlab = deparse(substitute(x)), ylab = deparse(substitute(y))) : 
  'x' and 'y' lengths differ

enter image description here

Here's the code for tictactoe and its board shown afterward:

par(pty="s") # square plot type
x = rep(1:3, each = 3)
y = rep(1:3, times = 3)
symbols(x, y, squares=rep(1, times=9),
        inches=FALSE, # match squares to axes
        xlim=c(0,4),
        ylim=c(4,0)) # flip y axis to match matrix format
board = matrix(rep("E", times=9), nrow=3, ncol=3)

enter image description here

After changing line 2 and 3 to the following:

x = rep(1:6, each = 7); y = rep(1:7, times = 6)

I got the following plot. Do you know why the horizontal lines are like so? and not sharp and they are blurred? enter image description here

Was it helpful?

Solution

par(pty="s") # square plot type
x = rep(1:7, each = 6)
y = rep(1:6, times = 7)
symbols(x, y, squares = rep(1, times=42),
        inches=FALSE, # match squares to axes
        xlim=c(0,8),
        ylim=c(8,0),
        axes = FALSE,
        xlab = '', ylab = '') # flip y axis to match matrix format
board = matrix(rep("E", times=42), nrow = 6, ncol = 7)

enter image description here

You can add the axes and ticks and labels back in if you like

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top