as_npc: Convert Character Coordinates into Normalized Parent...

View source: R/as_npc.R

as_npcR Documentation

Convert Character Coordinates into Normalized Parent Coordinates (NPC)

Description

Convert character coordinates to npc units and shift postions to avoid overlaps when grouping is active. If numeric validate npc values.

Usage

as_npc(
  value,
  group = 1L,
  step = 0.1,
  margin.npc = 0.05,
  axis = c("xy", "x", "y")
)

as_npcx(value, group = 1L, step = 0.1, margin.npc = 0.05)

as_npcy(value, group = 1L, step = 0.1, margin.npc = 0.05)

Arguments

value

numeric (in [0-1]) or character vector of coordinates. If character, should be one of c('right', 'left', 'bottom', 'top', 'center', 'centre', 'middle').

group

integer ggplot's group id. Used to shift coordinates to avoid overlaps.

step

numeric value in [0-1]. The step size for shifting coordinates in npc units. Considered as horizontal step for x-axis and vertical step for y-axis. For y-axis, the step value can be negative to reverse the order of groups.

margin.npc

numeric [0-1] The margin added towards the nearest plotting area edge when converting character coordinates into npc.

axis

the concerned axis . Should be one of c("xy", "x", "y").

Details

the as_npc() function is an adaptation from ggpmisc::compute_npc().

Value

A numeric vector with values in the range [0-1] representing npc coordinates.

Functions

  • as_npc(): converts x or y coordinate values into npc. Input values should be numeric or one of the following values c('right', 'left', 'bottom', 'top', 'center', 'centre', 'middle').

  • as_npcx(): converts x coordinate values into npc. Input values should be numeric or one of the following values c('right', 'left', 'center', 'centre', 'middle'). Wrapper around as_npc(axis = "x").

  • as_npcy(): converts y coordinate values into npc. Input values should be numeric or one of the following values c( 'bottom', 'top', 'center', 'centre', 'middle'). Wrapper around as_npc(axis = "y").

See Also

npc_to_data_coord, get_coord.

Examples

as_npc(c("left", "right"))
as_npc(c("top", "right"))


kassambara/ggpubr documentation built on Feb. 15, 2023, 4:09 a.m.