scale_vec_length_to_mm: Scale length of vector to given mm

Description Usage Arguments Examples

View source: R/utils.R

Description

This function will scale a vector in usr coordinates to mm so the plotted length will be as desired. This will be particularly useful in situtations where the plot aspect ratio is unequal to 1.

Usage

1

Arguments

v

A 2D vector

mm

Numeric. Length to standardize vector to in mm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
par(mfrow=c(1,2))

plot(NULL, xlim=c(-1,1), ylim=c(-1,1), asp=2,
     main="vectors plot length\n varies by direction")

rs <- seq(0, 2*pi, length=41)
v = c(1,0)
for (r in rs) {
  R = rotation_matrix_2d(r, clockwise = F)  
  n = v %*% R
  segments(0,0, n[1], n[2]) 
}

plot(NULL, xlim=c(-1,1), ylim=c(-1,1), asp=2,
     main="vectors have 10mm plot\nlength in all directions")
for (r in rs) {
  R = rotation_matrix_2d(r, clockwise = F)  
  n = v %*% R
  b = scale_vec_length_to_mm(n, mm=10)
  segments(0,0, b[1], b[2]) 
}

markheckmann/dissertation documentation built on May 21, 2019, 12:06 p.m.