gpt4 book ai didi

r - 错误 : Too few points to calculate an ellipse with 3 points?-R

转载 作者:行者123 更新时间:2023-12-05 03:06:06 34 4
gpt4 key购买 nike

你好。我正在策划 pcafactoextra包裹。我对每个因素有 3 分,并想在每个因素周围画椭圆。但我收到错误 Too few points to calculate an ellipse .

可以在 ggplot2 中围绕 3 个点绘制椭圆与 stat_ellipse功能。我可以通过查看 calculate_ellipse 来确认这一点code来自 ggplot2那说else if (dfd < 3) {message("Too few points to calculate an ellipse") .那么椭圆函数是什么factoextrafviz_pca_ind 中使用它认为 3 分太少?有没有办法强制它添加省略号?该软件包具有我需要的特定功能,因此我想坚持使用它。谢谢。

library(factoextra)

data(iris)

iris2<-iris[c(1:3,51:53,101:103),] # 3 points for each factor

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

fviz_pca_ind(res.pca, label='none',alpha.ind = 1,
habillage=iris2$Species,
repel = TRUE,
addEllipses = TRUE,invisible='quali')+
theme(legend.position = 'bottom')+
coord_equal()

#Too few points to calculate an ellipse
#Too few points to calculate an ellipse
#Too few points to calculate an ellipse

enter image description here

最佳答案

我遇到了同样的问题。解决方案是使用 ggforce 中的 geom_mark_ellipse包裹。可以围绕 3 个点(甚至围绕 1 个点)创建一个椭圆。

因此,工作流程应该如下:

library(factoextra)
library(ggforce)

data(iris)

iris2<-iris[c(1:3,51:53,101:103),] # 3 points for each factor

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

fviz_pca_ind(res.pca, label='none',alpha.ind = 1,
habillage=iris2$Species,
repel = TRUE,
# Don't use default Ellipses!!!!
# addEllipses = TRUE,
invisible='quali') +
# ADD ggforce's ellipses
ggforce::geom_mark_ellipse(aes(fill = Groups,
color = Groups)) +
theme(legend.position = 'bottom') +
coord_equal()

enter image description here

关于r - 错误 : Too few points to calculate an ellipse with 3 points?-R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49931681/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com