gs_coords_unit() returns the physical length of one unit of the input
coordinates, and gs_coords_unit<- sets it. gs_coords_extent()
returns the width and height of the plotted area, in coordinate units or in
a physical unit; gs_coords likewise returns the coordinates.
The unit is metadata: it does not change the coordinates, and it is
preserved across normalization, cropping, rotation and other transformations.
Usage
# S4 method for class 'GraphSpaceInterface'
gs_coords_unit(x) <- value
# S4 method for class 'GraphSpaceInterface'
gs_coords_unit(x, as_units = FALSE)
# S4 method for class 'GraphSpaceInterface'
gs_coords_extent(x, raw = FALSE, unit = NULL)Arguments
- x
A GraphSpace object.
- value
The physical length of one unit of the input coordinates, i.e. the coordinates as provided (e.g.
gs_vertex_attr(x, "x")): a single named number, such asc(um = 0.2125); a unit name, such as"um", for one unit of that length; or aunitsobject. OrNULLto remove the unit.- as_units
For
gs_coords_unit(): a single logical value. IfTRUE, return aunitsobject (requires the units package).- raw
For
gs_coords_extent(): a single logical value, as ings_coords. IfFALSE(default), the coordinates are the current coordinates,gs_coords(x)(e.g. of the normalized \([0, 1]\) space); ifTRUE, the raw coordinates,gs_coords(x, raw = TRUE).- unit
For
gs_coords_extent(): a length unit, such as"um"or"mm";NULL(default) means coordinate units.
Value
gs_coords_unit() returns a named number (or a units object),
or NULL if no unit is set. gs_coords_extent() returns a named
vector, width and height; it stops with an error if a
unit is requested and none is set.
gs_coords_unit<- returns the updated GraphSpace object.
Details
Metric units are built in: "nm", "um" (micrometer),
"mm", "cm", "m" and "km"; micrometers can
also be named with the micro sign (\(\mu\)m) or as "micron".
Any other length unit, such as the imperial "mi" or "ft",
is handled by the units package, using its unit names.
Geographic coordinates in degrees (longitude, latitude) are not lengths,
and a degree of longitude has no constant length: project such
coordinates first (e.g. with sf::st_transform()), then set the
unit of the projected coordinates.
Like the scale factor (gs_scale_factor), the unit
describes the input coordinates, i.e. the coordinates as provided: it is
returned as set, and can be set or corrected at any time.
gs_coords(x, raw, unit) and gs_coords_extent(x, raw, unit)
follow the same rule: raw selects the coordinates, and unit
the physical unit. Physical lengths do not change with the scale factor,
normalization or cropping, although the coordinates do.
gs_coords_extent(x) is the size of the plotted area (the \([0, 1]\)
space once normalized), and gs_coords_extent(x, raw = TRUE) the
size of the data.
Examples
library(RGraphSpace)
data("gtoy1", package = "RGraphSpace")
gs <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...
# One graph-coordinate unit is 10 micrometers (a map would use, e.g.,
# c(km = 1) for coordinates projected in kilometers)
gs_coords_unit(gs) <- c(um = 10)
gs_coords_unit(gs)
#> um
#> 10
# After normalization, the unit of the input coordinates is unchanged
gs <- normalizeGraphSpace(gs)
#> Normalizing node coordinates to graph space...
gs_coords_unit(gs)
#> um
#> 10
# Coordinates in micrometers, current and raw
head(gs_coords(gs, unit = "um"))
#> x y
#> n1 92.5 72.5
#> n2 112.5 72.5
#> n3 72.5 92.5
#> n4 52.5 32.5
#> n5 12.5 72.5
head(gs_coords(gs, raw = TRUE, unit = "um"))
#> x y
#> n1 0 0
#> n2 20 0
#> n3 -20 20
#> n4 -40 -40
#> n5 -80 0
# Size of the plotted area, and of the data, in micrometers
gs_coords_extent(gs, unit = "um")
#> width height
#> 125 125
gs_coords_extent(gs, raw = TRUE, unit = "um")
#> width height
#> 100 60