Skip to contents

This layout places vertices on a rectangular grid, in two or three dimensions.

Usage

layout_on_grid(graph, width = 0, height = 0, dim = 2)

on_grid(...)

layout.grid.3d(graph, width = 0, height = 0)

Arguments

graph

The input graph.

width

The number of vertices in a single row of the grid. If this is zero or negative, then for 2d layouts the width of the grid will be the square root of the number of vertices in the graph, rounded up to the next integer. Similarly, it will be the cube root for 3d layouts.

height

The number of vertices in a single column of the grid, for three dimensional layouts. If this is zero or negative, then it is determinted automatically.

dim

Two or three. Whether to make 2d or a 3d layout.

...

Passed to layout_on_grid().

Value

A two-column or three-column matrix.

Details

The function places the vertices on a simple rectangular grid, one after the other. If you want to change the order of the vertices, then see the permute() function.

Author

Tamas Nepusz ntamas@gmail.com

Examples


g <- make_lattice(c(3, 3))
layout_on_grid(g)
#>       [,1] [,2]
#>  [1,]    0    0
#>  [2,]    1    0
#>  [3,]    2    0
#>  [4,]    0    1
#>  [5,]    1    1
#>  [6,]    2    1
#>  [7,]    0    2
#>  [8,]    1    2
#>  [9,]    2    2

g2 <- make_lattice(c(3, 3, 3))
layout_on_grid(g2, dim = 3)
#>       [,1] [,2] [,3]
#>  [1,]    0    0    0
#>  [2,]    1    0    0
#>  [3,]    2    0    0
#>  [4,]    0    1    0
#>  [5,]    1    1    0
#>  [6,]    2    1    0
#>  [7,]    0    2    0
#>  [8,]    1    2    0
#>  [9,]    2    2    0
#> [10,]    0    0    1
#> [11,]    1    0    1
#> [12,]    2    0    1
#> [13,]    0    1    1
#> [14,]    1    1    1
#> [15,]    2    1    1
#> [16,]    0    2    1
#> [17,]    1    2    1
#> [18,]    2    2    1
#> [19,]    0    0    2
#> [20,]    1    0    2
#> [21,]    2    0    2
#> [22,]    0    1    2
#> [23,]    1    1    2
#> [24,]    2    1    2
#> [25,]    0    2    2
#> [26,]    1    2    2
#> [27,]    2    2    2

plot(g, layout = layout_on_grid)

if (interactive() && requireNamespace("rgl", quietly = TRUE)) {
  rglplot(g, layout = layout_on_grid(g, dim = 3))
}