Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ngonGrob

Regular polygon grob


Description

Regular polygons with optional rotation, stretching, and aesthetic attributes.

Usage

ngonGrob(x, y, n = 5, size = 5, phase = pi/2, angle = 0, ar = 1,
  gp = gpar(colour = "black", fill = NA, linejoin = "mitre"), ...,
  position.units = "npc", size.units = "mm")

grid.ngon(...)

ellipseGrob(x, y, size = 5, angle = pi/4, ar = 1, n = 50,
  gp = gpar(colour = "black", fill = NA, linejoin = "mitre"), ...,
  position.units = "npc", size.units = "mm")

grid.ellipse(...)

polygon_regular(n = 5, phase = 0)

Arguments

x

x unit

y

y unit

n

number of vertices

size

radius of circumscribing circle

phase

angle in radians of first point relative to x axis

angle

angle of polygon in radians

ar

aspect ratio

gp

gpar

...

further parameters passed to polygonGrob

position.units

default units for the positions

size.units

grid units for the sizes

Value

A grob.

Functions

  • ngonGrob: return a polygon grob

  • grid.ngon: draw a polygon grob on the current device

  • ellipseGrob: return an ellipse grob

  • grid.ellipse: draw an ellipse grob

  • polygon_regular: return the x,y coordinates of a regular polygon inscribed in the unit circle

Examples

library(grid)
N <- 5
xy <- polygon_regular(N)*2

# draw multiple polygons
g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), 
              unit(xy[,2],"cm") + unit(0.5,"npc"),
              n = seq_len(N) + 2, gp = gpar(fill=1:N))

grid.newpage()
grid.draw(g)

# rotated and stretched
g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), 
              unit(xy[,2],"cm") + unit(0.5,"npc"),
              n = seq_len(N) + 2, ar = seq_len(N),
              phase = 0, angle = pi/(seq_len(N) + 2),
              size = 1:N + 5)

grid.newpage()
grid.draw(g2)

# ellipse
g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), 
                  unit(xy[,2],"cm") + unit(0.5,"npc"),
                  angle = -2*seq(0,N-1)*pi/5 + pi/2,
                  size = 5, ar = 1/3)

grid.newpage()
grid.draw(g3)

gridExtra

Miscellaneous Functions for "Grid" Graphics

v2.3
GPL (>= 2)
Authors
Baptiste Auguie [aut, cre], Anton Antonov [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.