我正在为 PCA 分数图制作脚本,但是我在每个椭圆的中心得到了未填充形状的人工制品,即使我将椭圆设置为 FALSE,也会出现这种情况。请有人帮助我理解为什么会发生这种情况以及如何解决它。
这是我的脚本;
colores <- c("red","purple","blue")
pointss <- c(23,22,21)
pcaData <- df[, -c(1)]
pcaData <- pcaData[, apply(pcaData, 2, var) != 0]
res.pca <- prcomp(pcaData, center = TRUE, scale. = TRUE) # Exclude the labels and symbols
labels <- df$stage
fviz_screeplot(res.pca)
fviz_pca_ind(
res.pca,
axes = c(1, 2),
label = "none",
habillage = labels,
addEllipses = TRUE,
ellipse.type = "confidence",
ellipse.level = 0.95,
ellipse.alpha = 0.05
) +geom_point(aes(fill=labels, shape=labels), color="black", size=6) +
scale_shape_manual(values=pointss) +
scale_fill_manual(values=colores) +
scale_color_manual(values=colores)
此图像但没有未填充的形状:。
意识到我的问题,我也在绘制质心,这样解决了。我还添加了一种更改轴以记录解释的方差的方法
`
factoextra::fviz_pca_ind(
res.pca,
habillage = factor(labels),
geom = "point",
col.ind = labels,
palette = colores,
shape.ind = as.factor(labels),
addEllipses = TRUE,
ellipse.type = "confidence",
ellipse.level = 0.95,
ellipse.alpha = 0.05,
pointsize = 2,
position = position_jitter(2),
mean.point=F #get rid of centrdo
) +
labs(title = "PCA Scores Plot",
x = paste("PC1 (", round(res.pca$sdev[1]^2 / sum(res.pca$sdev^2) * 100, 1), "%)"),
y = paste("PC2 (", round(res.pca$sdev[2]^2 / sum(res.pca$sdev^2) * 100, 1), "%)"))
`