rggplot2ggfortifybiplot

Modify point stroke on a PCA biplot using autoplot function


I am using the autoplot function to make a PCA biplot. In my case, I would like to increase the point stroke to improve the readability of the plot. How can I do that?

Here's an example:

library(ggfortify)
df <- iris[c(1, 2, 3, 4)]
autoplot(prcomp(df), data = iris, colour="Species", fill="Species", shape="Species", geom="points", size=2) +
  scale_color_manual(values=c("#1B9E77","#D95F02","#7570B3")) +
  scale_fill_manual(values=c("#ffffff","#ffffff","#ffffff")) +
  scale_shape_manual(values=c(21:23))

enter image description here


Solution

  • I found the solution to my problem by adding the last line of code to the plot:

    library(ggfortify)
    df <- iris[c(1, 2, 3, 4)]
    p <- autoplot(prcomp(df), data = iris, colour="Species", fill="Species", shape="Species", geom="points", size=2) +
      scale_color_manual(values=c("#1B9E77","#D95F02","#7570B3")) +
      scale_fill_manual(values=c("#ffffff","#ffffff","#ffffff")) +
      scale_shape_manual(values=c(21:23))
    p$layers[[1]]$aes_params$stroke <- 2
    p
    

    enter image description here