0

I use the iris dataset as an example. I have set mean.point-TRUE which gives mean points for setosa (red round), versicolor (green triangle), virginica (blue square) as well as the factors (steelblue dot). I wish to make the steelblue dot to not appear while keeping everything else as is. How do I do this?

Here is the code:

library(tidyverse)
library(factoextra)
library(FactoMineR)


Groups<-as.factor(iris$Species)
res.pca<-prcomp(iris[-5], scale. = TRUE, center = TRUE)
fviz_pca_biplot(res.pca,
                mean.point=TRUE,
                pointsize=1,
                habillage=Groups,
                addEllipses = TRUE,
                label = FALSE)

And here is the output:

PCA_biplot

I_O
  • 4,983
  • 2
  • 2
  • 15
Ginko-Mitten
  • 304
  • 1
  • 11

1 Answers1

1

You can assign separate sizes to mean points. In your example, the blue point is the mean of the third group, so you can set the third position of the size vector to zero to hide the point:

fviz_pca_biplot(## ... other arguments
                ## but without mean.point
                mean.point.size = c(5, 5, 0)
                )

(leave out the mean.point argument entirely, i. e. neither setting it to TRUE, FALSE or any other missingness value)

I_O
  • 4,983
  • 2
  • 2
  • 15
  • 1
    I used your modification, but got the error `Error: ! Problem while setting up geom aesthetics. ℹ Error occurred in the 3rd layer. Caused by error in `check_aesthetics()`: ! Aesthetics must be either length 1 or the same as the data (3) ✖ Fix the following mappings: `size` Run `rlang::last_trace()` to see where the error occurred.` – Ginko-Mitten Jun 12 '23 at 09:18
  • 1
    Turned out, one has to skip the `mean.point` argument, see edit please. – I_O Jun 12 '23 at 10:46
  • Firstly, thanks for responding to my query so patiently. This is my code where the mean.point has been commented out: `fviz_pca_biplot(res.pca, pointsize=1, # mean.point=TRUE, mean.point.size = c(5, 5, 0), habillage=Groups, mean.point.size = 4, addEllipses = TRUE, label = FALSE)` And I get the error: `Error in ggpubr::ggscatter(data = df, x = "x", y = "y", color = color, : formal argument "mean.point.size" matched by multiple actual arguments` – Ginko-Mitten Jun 12 '23 at 13:19
  • 1
    :-) In your above comment, you set `mean.point.size` twice (before and after the `habillage` argument). Hence the "multiple arguments" error. – I_O Jun 12 '23 at 13:28
  • Do I feel dumb! Thanks a lot. It fixed my issues. I have a presentation in coming up tomorrow and this was really bothering me! Can't thank you enough! – Ginko-Mitten Jun 12 '23 at 16:46
  • you're welcome - and good luck with the presentation! Unless you're using it already, you might like Xaringan presentations (to go with RMarkdown) for the wow-factor: https://slides.yihui.org/xaringan/#1 – I_O Jun 12 '23 at 17:09
  • Wow! Thanks for the suggestion. I usually use LaTeX. I'll tinker with this soon. – Ginko-Mitten Jun 12 '23 at 19:07