library('factoextra')
data('mtcars')
pca.cars <- PCA(mtcars)
gg <- factoextra::fviz_pca_biplot(X = pca.cars,
# samples
fill.ind = mtcars$vs , col.ind = 'black',
pointshape = 21, pointsize = 1.5,
geom.ind = 'point', repel = T,
geom.var = FALSE )
mtcars$brand <- row.names(mtcars)
In the plot gg
I want a text label on the point for Valiant
in mtcars$brand
.
I already tried this approach, which only gives me the desired point. But I want the same plot, but with a text label on the Valiant
point
gg$layers[[1]]$data <- dplyr::filter(gg$layers[[1]]$data, name == "Valiant")
gg$layers[[2]]$data <- dplyr::filter(gg$layers[[2]]$data, name == "Valiant")
Thank you!
This could be achieved like so. Instead of extracting the coordinates via
gg$layers
you canPCA()
.geom_text
layer to label the desired points