Change decimals for proportion of variance displayed in autoplot PCA

110 views Asked by At

I would like to change the number of decimals for the Proportion of Variance displayed in the axes of a PCA plot using prcomp() and autoplot(). By default it's set to 2 decimals places (92.46%, 5.31%) but I'd like to round them to 1 decimal place (92.5%, 5.3%).

library(ggfortify)
df <- iris[1:4]
pca <- prcomp(df)
autoplot(pca)

Thank you!

1

There are 1 answers

0
Michael On

First, disable the default variance percentage displayed by using:

autoplot(pca, variance_percentage = FALSE)

Then add the labels you want using:

autoplot(pca, variance_percentage = FALSE) +
  xlab("PC1 (%)")