Description Usage Arguments Details Examples
Add labels to an axis at given positions
1 2 |
v |
Direction vector of axis. |
U |
Points on axis in user coordinates |
labels |
Labels to place on axis. |
i |
Indexes of which labels to plot. |
ortho |
Labels orthogonal to axis? (default |
below |
Should the label appear below the axis? |
line |
Number of lines label is placed below axis. |
srt |
A numerical value specifying (in degrees) how the text should be rotated. |
... |
Passed on to |
Places value labels at given points and in direction given by vector. The labels are rotated automatically to be readable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # generate data
set.seed(1)
v <- c(1,1) # vector in direction of axis
X <- t(replicate(4, runif(1, -1, 1) * v)) # generate points on axis
## plot 1: add labels parallel to axis
plot(X, pch=16, asp=1, xlim=c(-1,1), ylim=c(-1,1))
abline(h=0, v=0, col="grey")
abline(0, 1)
# add point coords as labels
lbls <- apply(X, 1, function(x) paste(round(x,1), collapse=","))
add_axes_labels(v, X, lbls, cex=.7)
## plot 2: add labels perpendicular to axis / without rotation
plot(X, pch=16, asp=1, xlim=c(-1,1), ylim=c(-1,1))
abline(h=0, v=0, col="grey")
abline(0, 1)
# add projected values on vector as labels
vn <- v / sum(v^2)^.5 # normalize vector for projection
lbls <- X %*% v # project points on vector
add_axes_labels(v, X, round(lbls,1), cex=.7,
below=FALSE, col="blue", ortho=TRUE)
add_axes_labels(v, X, round(lbls, 1), cex=.7, srt=0,
line = .5, col="grey")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.