Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the font size of data label in fviz_pca_var of factoextra

Tags:

r

ggplot2

When I submitted a paper to a journal, the journal asked me to set the font size to 7.5, however when I used the following code, only the axis text changed, the label size remained unchanged,

    library(ggplot2)
    library(FactoMineR)
    library(factoextra)

    irispca <- PCA(iris,quali.sup = 5)
    fviz_pca_var(irispca)+
   theme(text = element_text(size = 7.5),
         axis.title = element_text(size = 7.5),
         axis.text = element_text(size = 7.5)
         )

Any suggestion is appreciated to tell what code should I used to change the label size?

enter image description here

like image 425
Minyi Han Avatar asked May 18 '18 13:05

Minyi Han


People also ask

How do I change font size in labels?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.

How do I change font size in Xlabel?

xlabel(___, Name,Value ) modifies the label appearance using one or more name-value pair arguments. For example, 'FontSize',12 sets the font size to 12 points.


2 Answers

Getting into fviz_pca_var looks like you can just pass a labelsize in the function:

irispca <- PCA(iris,quali.sup = 5)
fviz_pca_var(irispca, labelsize = 3, repel = TRUE) +
  theme(text = element_text(size = 7.5),
        axis.title = element_text(size = 7.5),
        axis.text = element_text(size = 7.5))

enter image description here

like image 54
SCDCE Avatar answered Oct 15 '22 03:10

SCDCE


The argument labelsize is passed as an aditional argument to the fviz() function. If you then go to the fviz help page, the argument is there.

I would rather add a comment to the above answer but I do not have the required reputation so pardon me...

like image 38
Igor Salerno Filgueiras Avatar answered Oct 15 '22 03:10

Igor Salerno Filgueiras