noteworthy
library(heplots)
library(dplyr)
library(ggplot2)
library(ggbiplot)
library(factoextra)
data(peng, package="heplots")
# find potential multivariate outliers
DSQ <- heplots::Mahalanobis(peng[, 3:6])
noteworthy <- order(DSQ, decreasing = TRUE)[1:3] |> print()
[1] 283 10 35
ggbiplot
不允许点和标签。
这是使用factoextra::fviz_pca_biplot
的尝试。我创建了一个矢量lab
,只有这3个案例编号非空白。 但是,当我尝试在呼叫中使用它时,图中都有任何标签。
peng.pca <- prcomp (~ bill_length + bill_depth + flipper_length + body_mass,
data=peng, scale. = TRUE)
# create vector of labels, blank except for the noteworthy
lab <- 1:nrow(peng)
lab <- ifelse(lab %in% noteworthy, lab, "")
fviz_pca_biplot(
peng.pca,
axes = 3:4,
habillage = peng$species,
addEllipses = TRUE, ellipse.level = 0.68,
palette = peng.colors("dark"),
arrowsize = 1.5, col.var = "black", labelsize=4,
# label = lab
) +
theme(legend.position = "top")
您可以使用geom_text
层,在其中将