来自ggfortify :: ggbiplot的警告消息

时间:2017-03-20 20:09:21

标签: r ggplot2 warnings ggbiplot ggfortify

我正在尝试使用ggbiplot包中的ggfortify。它似乎工作正常,但我收到如下警告信息,

mdl <- pls::plsr(mpg ~ ., data = mtcars, scale = T)
scrs <- data.frame(pls::scores(mdl)[])
loads <- data.frame(pls::loadings(mdl)[])

ggfortify::ggbiplot(scrs, loads, 
  label.label = rownames(scrs), asp = 1, label = T, label.size = 3,
  loadings = T, loadings.label = T, loadings.label.label = rownames(loads))

Warning messages:
1: In if (value %in% columns) { :
  the condition has length > 1 and only the first element will be used
2: In if (value %in% columns) { :
  the condition has length > 1 and only the first element will be used

我采取了错误的步骤还是错误。

1 个答案:

答案 0 :(得分:1)

根据ggbiplot文档,label.label=参数需要从中提取名称的列名;它不期望一个名字的向量。同样适用于loadings.label.label=。 (ggplot和大多数tidyverse函数都不喜欢rownames - 更好地使它们成为一个合适的列)

scrs$ID <- rownames(scrs)
loads$ID <- rownames(loads)
ggfortify::ggbiplot(scrs, loads, 
  label.label = "ID", asp = 1, label = T, label.size = 3,
  loadings = T, loadings.label = T, loadings.label.label = "ID")