Description Usage Arguments Value Examples
Plot a board based on the inputted board matrix. Different values in the matrix represent squares of different colors. 0: black; 1: white; 2: lightblue
1 2 |
board: |
a board object. An error will occur if the inputted board is invalid. |
grid: |
if TRUE, the squares are plotted with grey, dashed outlines |
Returns the ggplot object visualizing the board.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | board_example <- board(matrix(c(0,1,1,1,0,
0,1,1,0,1,
0,0,1,0,0,
0,0,0,2,2,
2,2,2,2,0), 5, 5))
note the matrix will be the transpose of what you see here (due to byrow = F)
plot(board_example, grid=TRUE)
board_example2 <- board(matrix(c(0,1,1,1,0,
0,1,1,0,1,
0,0,1,0,0,
0,0,0,1,1,
1,1,1,1,0), 5, 5))
plot(board_example2, grid=TRUE)
board_example3 <- board(matrix(c(0,2,2,2,0,
0,2,2,0,2,
0,0,2,0,0,
0,0,0,2,2,
2,2,2,2,0), 5, 5))
plot(board_example3, grid=TRUE)
board_example4 <- board( # board of size 10 (correctly percolated)
matrix(c(2, 0, 0, 2, 0, 0, 2, 2, 0, 0,
2, 2, 2, 0, 0, 2, 2, 0, 0, 1,
0, 2, 0, 0, 0, 0, 2, 0, 0, 0,
0, 2, 2, 2, 0, 0, 0, 0, 0, 0,
0, 2, 0, 0, 0, 0, 1, 0, 0, 0,
2, 2, 2, 0, 1, 0, 0, 1, 1, 1,
0, 2, 2, 0, 1, 1, 0, 0, 1, 0,
1, 0, 2, 0, 0, 0, 0, 1, 1, 0,
1, 0, 0, 1, 1, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 1, 0, 1, 0, 0),
10, 10))
plot(board_example4, grid=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.