8

我一直在努力对fviz_pca来自 R 包的函数中的输出图中的默认点形状进行更改FactoExtra

该图以我要自定义的点形状的特定顺序*出现。

*对应的形状分别是16,17,15,12,0,8

    fviz_pca_biplot(PCA, axes = c(1, 2), 
            label="var", col.var = "black", #setas
            geom = "point", pointsize = 2, col.ind=PCADF$groups, 
            addEllipses = TRUE, ellipse.level = 0.95,
            ellipse.type ="confidence", palette = "aaas") + theme_minimal()

我尝试添加到该功能:

  geom_point(aes(shape = c(19,20,21,22,23,24)))

它给我返回了一条错误消息:

geom [1] 中的错误:“环境”类型的对象不是子集

在函数 fviz_pca 中管理和自定义点形状有什么建议吗?

4

1 回答 1

4

我们可以scale_shape_manual()像使用ggplot2对象一样使用:

library(factoextra)

data(iris)
res.pca <- prcomp(iris[, -5],  scale = TRUE)

fviz_pca_ind(res.pca,axes = c(1, 2), 
             label="var", col.var = "black", #setas
             geom = "point", pointsize = 2, col.ind=iris$Species, 
             addEllipses = TRUE, ellipse.level = 0.95,
             ellipse.type ="confidence", palette = "aaas") + theme_minimal()+
  scale_shape_manual(values=c(19,20,21))

在此处输入图像描述

于 2018-05-29T04:15:39.720 回答