This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Add borders to the shapes in the PCA plot by using autoplot

Hi,

I was able to plot the PCA between two different variables using function autoplot() function from ggfortify library. I have a question about how to add the black borders around the circles and triangles as shown in the plot below. Please let me know if there any specific function for adding?

Thank you,

Toufiq

## PCA on two variables##
pca_v1 <- prcomp(Node, scale. = TRUE)
autoplot(pca_v1,
         data = Neg_Dct, colour = 'Category', shape = 'Response' , size = 3.5) +
  theme_classic()

ggfortify r pca autoplot ggplot2

Try this code and let us have your comments here:

autoplot(pca_v1, data = Neg_Dct, colour = 'Category', shape = 'Response' , size = 3.5) +
geom_point(shape = 1,size = 3.5,colour = "black") +
theme_classic()

1 answer

We can achieve the same using basic ggplot, see example:

library(ggplot2)

#example data
df1 <- data.frame(
  x = 1:10,
  y = 1:10,
  grp = rep(LETTERS[1:2], 5)
)

ggplot(df1, aes(x, y, col = "black", fill = grp, shape = grp)) +
  geom_point() +
  scale_color_identity() +
  scale_fill_manual(values = c("red", "green")) +
  scale_shape_manual(values = c(21, 24)) +
  theme_classic()

We need to use shapes that can have colour and fill separately: http://www.sthda.com/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r

Log in to answer this question.