scaleBar: Add Scale Bar to Image

View source: R/scaleBar.R

scaleBarR Documentation

Add Scale Bar to Image

Description

Place a single horizontal scale bar pixels pixels wide corresponding to a physical distance distance with an optional label.

Usage

scaleBar(
  x,
  y = NULL,
  pixels,
  distance,
  label = NULL,
  col = "white",
  col.text,
  cex = 3/4,
  adj = c(0.5, -0.5),
  col.line,
  lwd = 1,
  lend = 1,
  xpd = NA,
  ...
)

Arguments

x, y

Central coordinates of the scale bar in pixels

pixels

Width of the scale bar in pixels

distance

Distance represented by the scale bar in microns

label

A suitable label that can be coerced to character or an expression. If NULL, a label will be generated from the distance argument. To exclude any label, set this argument to "" or to NA

col

Default color (white) for col.text and col.line

col.text, cex, adj, xpd, ...

Parameters passed to the text function used to add the label

col.line, lwd, lend

Parameters passed to the lines function used to draw the horizontal scale bar

Details

This is a utility to place a labeled scale bar on a raster image. A default label in microns will be added if label is NULL. The label is centered at the position specified by x,y according to the values in adj. The default value for adj of c(0.5,-0.5) centers the label and places it 0.5 character widths above x,y.

The x,y coordinates can be passed in a plotting structure appropriate for xy.coords. This function attempts to parse distance and pixels from the remaining arguments if they are not named and if x is a list with components named "x" and "y". This allows one to interactively place a scale bar with a function call such as in the following example. In this example, ppm stands for "pixels per micrometer" and is the scale factor appropriate for the given micrograph. This call will place a labeled 25 micron scale bar on the image.

> scaleBar(locator(), 25*ppm, 25)

Note that this is not a vectorized function. Only the last value of (x, y) will be used to place the scale bar. This allows multiple clicks to locator() to get the position just right with only the last click being used.

Pixels-per-micrometer calibration values for the Nikon TE300 at 1x1 binning with the QImaging camera are:

Objective   PPM value
 20X ELWD    3.098
 40X ELWD    6.157
 60X ELWD    9.414
 60X Apo     9.400
100X Apo    15.563
  4X Apo     0.62 (estimated)

Value

This function is called for side effects but the location is returned invisibly as a list.


ornelles/EBImageExtra documentation built on Aug. 10, 2022, 11:44 p.m.