I know how to produce a PCA plot through ggbiplot and this package works well.
But now I want to modify some specific points, such as their color, size and especially adding circles around some points but not cover them by geom_encircle()
function.
Here is my reproducible example code below:
#load required packages
library(ggplot2)
library(devtools)
library(ggbiplot)
#load dataset
data(iris)
#perform principal component analysis
pca = prcomp(iris[ , 1:4], scale=T)
#define classes, generate & view PCA biplot
class = iris$Species
ggbiplot(pca, obs.scale = 1, var.scale = 1, groups = class, circle = FALSE)+
geom_point(size = 3,aes(color = class))+
geom_point(data=iris[iris$Species=="setosa",],pch=21, fill=NA, size=2, colour="black", stroke=2)
However, error information appeared:
Error in `geom_point()`:
! Problem while computing aesthetics.
i Error occurred in the 5th layer.
Caused by error in `FUN()`:
! object 'xvar' not found
Run `rlang::last_trace()` to see where the error occurred.
I may know it is caused by data in geom_point()
which is not consistent to pca.
But I don't know how should I set the data in geom_point()
So I hope somebody could give me some advice or solutions.
Thanks in advance.