I am in the process of creating a small game using the R console, and I am trying to add consecutive numbering to my empty playing field (which should be adaptive to changes in n_row
and n_col
). The final output should something look like this:
Here is my current code:
n_row <- 4
n_col <- 4
# Plot empty playing field
par(xaxs = "i", yaxs = "i")
plot.new()
plot.window(xlim = c(0.5, 4.5), ylim = c(0.5, 4.5))
grid(nx = n_col, ny = n_row, col = "grey")
box(lwd = 2)
CodePudding user response:
You may use mtext
.
mtext(seq_len(n_row), at=seq_len(n_row), side=1, line=1, cex=1.5)
mtext(seq_len(n_col), at=seq_len(n_col), side=2, line=1, cex=1.5, las=2)
CodePudding user response:
Another solution, with axis
function
axis(side=1, at=1:4, labels=1:4, cex.axis=2, tick=FALSE)
axis(side=2, at=1:4, labels=1:4, cex.axis=2, las=2, tick=FALSE)