错误:要计算3个点的椭圆数太少?-R [英] Error: Too few points to calculate an ellipse with 3 points? - R

查看:329
本文介绍了错误:要计算3个点的椭圆数太少?-R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

G'day.我正在用 factoextra 软件包绘制一个 pca .我对每个因子有3分,并希望在每个因子周围画一个椭圆.但是我得到的错误是计算椭圆的点太少.

可以使用 stat_ellipse 函数在 ggplot2 中围绕3个点绘制椭圆.我可以通过查看 calculate_ellipse

解决方案

我遇到了同样的问题.解决方案是使用

G'day. I am plotting a pca with the factoextra package. I have 3 points for each factor and would like to draw ellipses around each. But I am getting the error Too few points to calculate an ellipse.

It is possible to draw ellipses around 3 points in ggplot2 with the stat_ellipse function. I can confirm this by looking at the calculate_ellipse code from ggplot2 that says else if (dfd < 3) {message("Too few points to calculate an ellipse"). So what ellipse function is factoextra using in fviz_pca_ind that it considers 3 points too few? Is there a way I can force it to add ellipses? This package has specific features I need so would like to stick with it. Thanks.

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

解决方案

I've faced the same problem. The solution is to use geom_mark_ellipse from ggforce package. It's possible to create an ellipse around 3 points (even around 1 point).

So, the workflow should be as follows:

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()

这篇关于错误:要计算3个点的椭圆数太少?-R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆