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

ggplot2问题:使用geom_polygon()无法填充椭圆

问题:ggbiplot组椭圆填充无效,需实现可选填充功能
  • 我正在维护ggbiplot包的新版本,目前遇到的问题是无法为不同组的数据填充椭圆,该问题已记录在项目的Issue中。
  • 我在ggbiplot.r文件的261-268行附近,将geom_path()替换为geom_polygon()以实现组椭圆填充,但测试后发现无效果,椭圆仍未被填充。
  • 我希望将填充功能设为可选项,计划添加ellipse.fill = T/F/alpha参数,但需先解决当前填充无效的问题。
  • 我已参考过ggplot2散点图叠加椭圆填充的相关问题,不过我的椭圆是内部计算生成的。

相关代码片段

g <- g + geom_polygon(data = ell, 
                      aes(color = groups, 
                          fill = groups
                          ),
                      alpha = 0.4,    # MF: why doesn't this have any effect?
                      linewidth = ellipse.linewidth)

测试用例

remotes::install_github("friendly/ggbiplot")
library(ggbiplot)
data(wine, package="ggbiplot")
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, groups=wine.class,
         ellipse = TRUE, 
         ellipse.linewidth = 1.2,
         circle = TRUE,
         varname.color = "darkred",
         varname.size = 4) +
  theme_minimal() +
  theme(legend.direction = 'horizontal', legend.position = 'top')

运行结果

未填充的组椭圆

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 02:15:14