offsetGridText-deprecated: Insert offset text annotation into 'trellis' plot

offsetGridText-deprecatedR Documentation

Insert offset text annotation into 'trellis' plot

Description

This is a wrapper function around calcOffsetGridText and grid-based text drawing functions (currently including grid.text and grid.stext) that automatically adds offset text annotations to a 'trellis' plot.

Usage

offsetGridText(x, y = NULL, labels, xlim = NULL, ylim = NULL, 
pos = NULL, stext = FALSE, offset = 0.02, ...)

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.

labels

Character. The text to be written.

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.

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.

stext

Logical. If TRUE, shadow text will be drawn (see grid.stext) instead of ordinary grid.text.

offset

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

...

Further arguments passed on the chosen grid text drawing function.

Author(s)

Florian Detsch

See Also

Rsenal-deprecated

Examples

## Not run: 
#' bing satellite image of mt. kilimanjaro
rst_kili <- kiliAerial(minNumTiles = 12,
                       projection = "+init=epsg:4326")
spl_kili <- rgb2spLayout(rst_kili, alpha = .8)

#' kilimanjaro peaks
kibo <- c(-3.065053, 37.359031)
mawenzi <- c(-3.095436, 37.455061)
shira <- c(-3.038222, 37.210408)

mat_peaks <- rbind(kibo, mawenzi, shira)
df_peaks <- data.frame(peak = c("Kibo", "Mawenzi", "Shira"), 
                       x = mat_peaks[, 2], 
                       y = mat_peaks[, 1])

coordinates(df_peaks) <- ~ x + y
projection(df_peaks) <- "+init=epsg:4326"

#' visualization
library(latticeExtra)

xlim_kili <- c(37.15, 37.55)
ylim_kili <- c(-3.25, -2.9)

p_kili <- spplot(df_peaks, auto.key = FALSE, col.regions = "white", 
                 xlim = xlim_kili, ylim = ylim_kili, cex = 2, pch = 20,
                 scales = list(draw = TRUE), sp.layout = spl_kili) + 
  layer(sp.points(df_peaks, cex = 1.5, pch = 20, col = "black"))

print(p_kili)

library(grid)
downViewport(trellis.vpname(name = "figure"))
offsetGridText(x = coordinates(df_peaks), labels = c("Kibo", "Mawenzi", "Shira"),  
               xlim = xlim_kili, ylim = ylim_kili, stext = TRUE, offset = .02,
               gp = gpar(fontsize = 20, fontfamily = "Bookman Old Style"))

## End(Not run)
  

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