You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言如何修改fviz_pca_biplot椭圆边框颜色或移除边框?

解决PCA双图椭圆边框颜色不匹配或移除边框的问题

报错原因

ellipse.border.remove并非fviz_pca_biplot的直接参数,它属于ggpubr::ggscatter的参数,但fviz_pca_biplot内部调用ggscatter时已传递相关参数,导致重复匹配引发报错。


方案1:让椭圆边框颜色匹配palette

在fviz_pca_biplot中添加col.ellipse = Data$Type参数,使椭圆边框与点的填充色使用同一套调色板:

biplot <- fviz_pca_biplot(pca_result,
                # Individuals
                geom.ind = "point",
                fill.ind = Data$Type, col.ind = "black",
                pointshape = 21, pointsize = 2,
                palette = c("#04BF8A","#D7D7D9"),
                addEllipses = TRUE,
                col.ellipse = Data$Type, # 椭圆边框匹配分组颜色
                # Variables
                col.var = "black",
                legend.title = "Type",
                repel = TRUE,
                xlim = c(-5,14),
                ylim = c(-3,8),
                ) +
xlab("PC1 (74.5%)") + ylab("PC2 (16.6%)")

biplot + theme_bw()

如果需要精确指定边框颜色,也可以直接传入palette的色值:

col.ellipse = c("#04BF8A","#D7D7D9")

方案2:直接移除椭圆边框

通过设置col.ellipse = NA让边框透明,实现移除效果:

biplot <- fviz_pca_biplot(pca_result,
                # Individuals
                geom.ind = "point",
                fill.ind = Data$Type, col.ind = "black",
                pointshape = 21, pointsize = 2,
                palette = c("#04BF8A","#D7D7D9"),
                addEllipses = TRUE,
                col.ellipse = NA, # 隐藏椭圆边框
                # Variables
                col.var = "black",
                legend.title = "Type",
                repel = TRUE,
                xlim = c(-5,14),
                ylim = c(-3,8),
                ) +
xlab("PC1 (74.5%)") + ylab("PC2 (16.6%)")

biplot + theme_bw()

也可以通过ellipse.size = 0达到相同的隐藏边框效果。

内容的提问来源于stack exchange,提问作者Cosmin Butnarasu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 12:22:44