如何选择性地标记在Biplot中使用factoextra :: fviz_pac_biplot或ggbiplot

问题描述 投票:0回答:1
数据。我想标记为

noteworthy

的3点。

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
层,在其中将

label矢量添加为使用例如,例如使用e.g的全局数据的列。 enter image description heredplyr::bind_cols

r ggplot2 pca biplot
1个回答
0
投票


    
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.