sHexGridVariant: Function to define a variant of a supra-hexagonal grid

Description Usage Arguments Value Note See Also Examples

Description

sHexGridVariant is supposed to define a variant of a supra-hexagonal map grid. In essence, it is the subset of the supra-hexagon.

Usage

1
2
3
4
5
6
7
sHexGridVariant(
r = NULL,
nHex = NULL,
shape = c("suprahex", "triangle", "diamond", "hourglass", "trefoil",
"ladder",
"butterfly", "ring", "bridge")
)

Arguments

r

an integer specifying the radius in a supra-hexagonal grid

nHex

the number of input hexagons in the grid

shape

the grid shape, either "suprahex" for the suprahex itself, or its variants (including "triangle" for the triangle-shaped variant, "diamond" for the diamond-shaped variant, "hourglass" for the hourglass-shaped variant, "trefoil" for the trefoil-shaped variant, "ladder" for the ladder-shaped variant, "butterfly" for the butterfly-shaped variant, "ring" for the ring-shaped variant, and "bridge" for the bridge-shaped variant)

Value

an object of class "sHex", a list with following components:

Note

none

See Also

sHexGrid

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
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# For "supraHex" shape itself
sHex <- sHexGridVariant(r=6, shape="suprahex")

## Not run: 
library(ggplot2)

#geom_polygon(color="black", fill=NA)

# For "supraHex" shape itself
sHex <- sHexGridVariant(r=6, shape="suprahex")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_suprahex <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="suprahex (r=6; xdim=ydim=11)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "triangle" shape
sHex <- sHexGridVariant(r=6, shape="triangle")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_triangle <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="triangle (r=6; xdim=ydim=6)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "diamond" shape
sHex <- sHexGridVariant(r=6, shape="diamond")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_diamond <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="diamond (r=6; xdim=6, ydim=11)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "hourglass" shape
sHex <- sHexGridVariant(r=6, shape="hourglass")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_hourglass <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="hourglass (r=6; xdim=6, ydim=11)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "trefoil" shape
sHex <- sHexGridVariant(r=6, shape="trefoil")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_trefoil <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="trefoil (r=6; xdim=ydim=11)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "ladder" shape
sHex <- sHexGridVariant(r=6, shape="ladder")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_ladder <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="ladder (r=6; xdim=11, ydim=6)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "butterfly" shape
sHex <- sHexGridVariant(r=6, shape="butterfly")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_butterfly <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="butterfly (r=6; xdim=ydim=11)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "ring" shape
sHex <- sHexGridVariant(r=6, shape="ring")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_ring <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="ring (r=6; xdim=ydim=11)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# For "bridge" shape
sHex <- sHexGridVariant(r=6, shape="bridge")
df_polygon <- sHexPolygon(sHex)
df_coord <- data.frame(sHex$coord, index=1:nrow(sHex$coord))
gp_bridge <- ggplot(data=df_polygon, aes(x,y,group=index)) +
geom_polygon(aes(fill=factor(stepCentroid%%2))) +
coord_fixed(ratio=1) + theme_void() + theme(legend.position="none") +
geom_text(data=df_coord, aes(x,y,label=index), color="white", size=3) +
labs(title="bridge (r=6; xdim=11, ydim=6)") +
theme(plot.title=element_text(hjust=0.5,size=8))

# combined visuals
library(gridExtra)
grid.arrange(grobs=list(gp_suprahex, gp_ring, gp_diamond, gp_trefoil,
gp_butterfly, gp_hourglass, gp_ladder, gp_bridge, gp_triangle),
layout_matrix=rbind(c(1,1,2,2,3),c(1,1,2,2,3),c(4,4,5,5,6),c(4,4,5,5,6),c(7,7,8,8,9)),
nrow=5, ncol=5)

## End(Not run)

hfang-bristol/supraHex documentation built on May 24, 2021, 3:13 p.m.