J.C*_*Con 4 plot r ellipse ggplot2 pca
日安。我正在绘制一个pca包factoextra。我对每个因素有 3 分,并且想在每个因素周围画上椭圆。但我收到了错误Too few points to calculate an ellipse。
ggplot2使用该函数可以在 3 个点周围绘制椭圆stat_ellipse。我可以通过查看其中的calculate_ellipse 代码来确认这一点。那么,使用什么椭圆函数来认为 3 个点太少了呢?有没有办法强制它添加省略号?该软件包具有我需要的特定功能,因此我想坚持使用它。谢谢。ggplot2else if (dfd < 3) {message("Too few points to calculate an ellipse")factoextrafviz_pca_ind
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
Run Code Online (Sandbox Code Playgroud)
我也遇到过同样的问题。geom_mark_ellipse解决方案是从包中使用ggforce。可以在 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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9504 次 |
| 最近记录: |