plot.board: Board Visualization

Description Usage Arguments Value Examples

View source: R/visualize.R

Description

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

Usage

1
2
## S3 method for class 'board'
plot(board, grid = TRUE)

Arguments

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

Value

Returns the ggplot object visualizing the board.

Examples

 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)

lilinhonglexie/percolate documentation built on Nov. 4, 2019, 4:32 p.m.