Add borders to the shapes in the PCA plot by using autoplot
1
1
Entering edit mode
4.9 years ago

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 • 3.4k views
ADD COMMENT
1
Entering edit mode

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()
ADD REPLY
2
Entering edit mode
4.9 years ago
zx8754 12k

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

ADD COMMENT

Login before adding your answer.

Traffic: 1808 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6