calcOffsetGridText-deprecated: Calculate offset coordinates for grid-based text annotations

calcOffsetGridText-deprecatedR Documentation

Calculate offset coordinates for grid-based text annotations

Description

Calculate offset coordinates for (grid-based) text drawing functions, e.g. grid.text.

Usage

calcOffsetGridText(x, y = NULL, offset = 0.02, pos = NULL
, xlim = NULL, ylim = NULL)

Arguments

x

Numeric. A vector containing x coordinates, or a 2-column matrix containing x and y coordinates.

y

Numeric. A vector containing y coordinates, or NULL if x is a two-column matrix.

offset

Numeric. The desired offset in normalized parent coordinates ("npc", see unit).

pos

Integer. Text position specifier(s) as used by text. If not supplied, optimal text positions will be determined with respect to neighboring locations using thigmophobe.

xlim

Numeric. X-axis limits (xmin, xmax) of the current plot. If not supplied, limits are automatically calculated from supplied x and y coordinates.

ylim

Numeric. Y-axis limits (ymin, ymax) of the current plot. If not supplied, limits are automatically calculated from supplied x and y coordinates.

Value

A numeric matrix containing offset coordinates.

Author(s)

Florian Detsch

See Also

Rsenal-deprecated

Examples

## Not run: 
# required packages
library(grid)
library(plotrix)
library(lattice)

# sample point data
x_cntr <- 330000
y_cntr <- 9650000

ls_xy <- lapply(c(x_cntr, y_cntr), function(i) {
  set.seed(i * 100)
  rnorm(10, i, 10000)
})

df <- data.frame(id = 1:10,
                 x = ls_xy[[1]],
                 y = ls_xy[[2]])
coordinates(df) <- ~ x + y
projection(df) <- "+init=epsg:21037"

# offset point locations
loc_lbl <- calcOffsetGridText(x = coordinates(df), offset = .015)

# vis
spplot(df, col.regions = "black", auto.key = FALSE)

downViewport(trellis.vpname(name = "figure"))
for (i in 1:nrow(df))
  grid.text(label = df$id[i], x = loc_lbl[i, 1], y = loc_lbl[i, 2],
            just = pos2just(thigmophobe(coordinates(df)))[i])

## End(Not run)
            

environmentalinformatics-marburg/Rsenal documentation built on July 28, 2023, 6:09 a.m.