geo_polygon | R Documentation |
geom
Create any (regular) polygon geometry (of class geom
) either by
specifying anchor values or by sketching it.
geo_polygon(
crds = NULL,
window = NULL,
features = 1,
vertices = 3,
regular = FALSE
)
geo_triangle(crds = NULL, window = NULL, features = 1)
geo_square(crds = NULL, window = NULL, features = 1)
geo_rectangle(crds = NULL, window = NULL, features = 1)
geo_hexagon(crds = NULL, window = NULL, features = 1)
as_polygon(geom)
crds |
data.frame(2) |
window |
data.frame(2) |
features |
integerish(1) |
vertices |
integerish(1) |
regular |
logical(1) |
geom |
gridded(1) |
The argument regular
determines how the vertices provided in
anchor
or via template
are transformed into a polygon:
if regular = FALSE
the resulting polygon is created
from all vertices in anchor
,
if regular = TRUE
, only
the first two vertices are considered, as centre and indicating the
distance to the (outer) radius.
A geom
.
geo_triangle()
: wrapper of geo_polygon where vertices = 3
and
regular = TRUE
.
geo_square()
: wrapper of geo_polygon where vertices = 4
and
regular = TRUE
.
geo_rectangle()
: wrapper of geo_polygon where vertices = 2
,
regular = FALSE
and the two complementing corners are derived from
the two given opposing corners.
geo_hexagon()
: wrapper of geo_polygon where vertices = 6
and
regular = TRUE
.
Other geometry shapes:
geo_line()
,
geo_point()
,
geo_random()
# 1. create a polygon programmatically
coords <- data.frame(x = c(0, 40, 40, 0),
y = c(0, 0, 40, 40))
# if no window is set, the bounding box will be set as window
polyGeom <- geo_polygon(crds = coords)
geo_vis(polyGeom)
# derive a regular polygon from the (first two) coordinates (per feature)
hexaGeom <- geo_polygon(crds = coords, vertices = 6, regular = TRUE)
geo_vis(hexaGeom, linecol = "green")
# 2. cast to point geom from another type
polyGeom <- as_polygon(geom = gtGeoms$point)
geo_vis(gtGeoms$point, linecol = "#FFB000", pointsymbol = 5)
geo_vis(polyGeom, linecol = "#33FF00", new = FALSE)
# 3. sketch a hexagon
if(dev.interactive()){
aHexagon <- geo_hexagon(features = 1)
geo_vis(aHexagon, linecol = "#33FF00", linetype = 2, new = FALSE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.