factoextra icon indicating copy to clipboard operation
factoextra copied to clipboard

removing legend from PCA plot ?

Open ShuonanChen opened this issue 7 years ago • 3 comments

Hi,

I am using function fviz_pca_ind, and was wondering if there's way to specify not showing the group legend. As advised in issue https://github.com/kassambara/factoextra/issues/20, I tried show.legend.text = FALSE, but didn't work, showing error:

"geom_text requires the following missing aesthetics: label"

My code looks like this:

res.pca <- prcomp(data, scale = TRUE)
fviz_pca_ind(res.pca, habillage = rownames(data), repel = TRUE) + 
  scale_colour_manual(values=my_color) +  geom_text(show.legend.text= F)

What am I doing wrong? Thank you!

Shuonan

ShuonanChen avatar Jan 20 '18 18:01 ShuonanChen

I had the same problem and how did you solve it? thanks!

dyinboisry4u avatar Aug 07 '19 09:08 dyinboisry4u

Have you tried:

fviz_pca_ind(res.pca, habillage = rownames(data), repel = TRUE) + scale_colour_manual(values=my_color) + theme(legend.position = "none")

It works with ggplot, therefore that is possible. Hope it works for you!

ghost avatar Aug 30 '20 00:08 ghost

I realise this might be too late for the original poster, but by adding +guides(shape=”none”, fill=”none”)
to the end of your fviz_pca_ind code, it should get rid of the Group legend.

sheepscientist avatar Sep 28 '23 08:09 sheepscientist