From 875119ee54b59624908d90d61b186b4a39480e26 Mon Sep 17 00:00:00 2001 From: Jari Oksanen Date: Mon, 3 Jul 2023 13:52:36 +0300 Subject: [PATCH 1/2] set numeric rownames if they were NULL scores(..., tidy=TRUE) failes with NULL rownames, and plot(..., type="t") shows nothing. --- R/print.wcmdscale.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/print.wcmdscale.R b/R/print.wcmdscale.R index 63b368ccf..84de2ab21 100644 --- a/R/print.wcmdscale.R +++ b/R/print.wcmdscale.R @@ -55,6 +55,8 @@ choices <- choices[choices <= NCOL(x$points)] x$points[, choices, drop = FALSE] } + if (is.null(rownames(p))) + rownames(p) <- as.character(seq_len(nrow(p))) if (tidy) { p <- data.frame(p, "scores" = "sites", "label" = rownames(p), "weight" = weights(x)) From dbf465265327d9580ee55501dff71660cc7e27d2 Mon Sep 17 00:00:00 2001 From: Jari Oksanen Date: Mon, 3 Jul 2023 14:03:40 +0300 Subject: [PATCH 2/2] take care that labels are not NULL when typ="t" is requested 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. --- R/ordiplot.R | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/R/ordiplot.R b/R/ordiplot.R index 36aaf457b..0bdc4b4a4 100644 --- a/R/ordiplot.R +++ b/R/ordiplot.R @@ -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) }