在R中绘制用于播放connect4的矩形板时出错

时间:2014-03-22 00:14:10

标签: r matrix plot par

我想基于我拥有的tictactoe板创建一个连接四板。然而事情听起来并不匹配,我的结果并不合适。 我想要6行7列!

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)

我收到此错误:

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

enter image description here

以下是tictactoe及其电路板的代码:

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

将第2行和第3行更改为以下内容后:

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

我得到了以下情节。你知道为什么水平线是这样的吗?并不尖锐,他们是模糊的? enter image description here

1 个答案:

答案 0 :(得分:1)

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

如果您愿意,可以重新添加轴,刻度和标签