【问题标题】:Error in drawing a rectangular board for playing connect4 in R绘制矩形板以在 R 中播放 connect4 时出错
【发布时间】:2014-03-22 00:14:09
【问题描述】:

我想根据我拥有的 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

下面是 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)

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

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

我得到了以下情节。你知道为什么水平线是这样的吗?并且不锐利并且它们模糊?

【问题讨论】:

  • 将第二、三行改为x = rep(1:6, each = 7); y = rep(1:7, times = 6)
  • @rawr 谢谢,更新了问题。
  • @rawr 但我想要 6 行和 7 列!

标签: r matrix plot par


【解决方案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)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    相关资源
    最近更新 更多