Skip to content

Commit

Permalink
take care that labels are not NULL when typ="t" is requested
Browse files Browse the repository at this point in the history
This is a belt & suspenders fix: scores.default should take care
that scores have rownames. However, scores.wcmdscale did not take
care (does now), and to protect against other careless scores
methods, we may have this here. Also gives a warning if text
labels were NULL before inventing new ones.
  • Loading branch information
jarioksa committed Jul 3, 2023
1 parent 875119e commit dbf4652
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions R/ordiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,22 @@
localPoints(Y, pch = "+", col = "red", cex = cex, ...)
}
if (type == "text") {
if (!is.null(X))
localText(X, labels = rownames(X), col = 1, cex = cex, ...)
if (!is.null(Y))
localText(Y, labels = rownames(Y), col = "red", cex = cex, ...)
if (!is.null(X)) {
labs <- rownames(X)
if (is.null(labs)) {
warning("type='t', but no names available: using x1...")
labs <- paste0("x", as.character(seq_len(nrow(X))))
}
localText(X, labels = labs, col = 1, cex = cex, ...)
}
if (!is.null(Y)) {
labs <- rownames(Y)
if (is.null(labs)) {
warning("type='t', but no names available: using y1...")
labs <- paste0("y", as.character(seq_len(nrow(Y))))
}
localText(Y, labels = labs, col = "red", cex = cex, ...)
}
}
out <- list(sites = X, species = Y)
}
Expand Down

0 comments on commit dbf4652

Please sign in to comment.