Search code examples
rellipseggbiplot

How to add ellipse center in ggbiplot?


I have data set seperated in 4 groups: groups = taxabylevel. I ran ggbiplot and add ellipses around each group. How to add centre of each ellipses?

g <- ggbiplot(pca, obs.scale = 1, var.scale = 1, alpha=0, groups = taxaBylevel,show_guide = FALSE, ellipse = TRUE)
print(g)

enter image description here


Solution

  • data(iris)
    
    pca<-prcomp(iris[,1:4],scale=T)
    
    
    g<-ggbiplot(pca, obs.scale = 1, var.scale = 1, alpha=0, groups = iris[,5],show_guide = FALSE, ellipse = TRUE)
    
    
    gmean=aggregate(g$data[,1:2],list(group=g$data$group),mean)
    
    ggbiplot(pca, obs.scale = 1, var.scale = 1, alpha=0, groups = iris[,5],show_guide = FALSE, ellipse = TRUE)+
      geom_point(data=gmean,aes(group=group,colour=group))
    

    enter image description here