factoextrabiplotggthemes

Using theme() from ggplot2 with the factoextra package to change aesthics of biplot made


I made a successful biplot using the factoextra package (fviz_pca_biplot()), but I want to change the size of the axis labels and titles as well as changing the color of the axis lines using ggtheme theme(). I used this code and nothing changes except the background goes from the default (gray and gridlines) to theme_classic (white background and no grids).

So, I get a biplot, but the theme() is not changing the aesthics of it.

I expected the biplot to have a different font size, the text bolded, the axis lines being red and having a size of 0.5 with a classic theme. All I got was the biplot with just the classic theme.

library(ggplot2)
library(factoextra)
ggplot2::theme()

B<-fviz_pca_biplot(PC.TM.Bact, repel = TRUE, geom=c('point'), select.var = list(contrib = 8),    title=NULL, col.var = "blue", col.ind.sup = "black",col.ind='blue', labelsize=7,loadinglabelsize=5, col.axes='blue', arrowsize=.5, pointsize=3, xlab="PC1 (33.1%)", ylab="PC2 (20.6%)") 
C<-B+theme(
      text = element_text(size = 20, face='bold'),
      panel.background = element_blank(),
      panel.grid.major = element_blank(), 
      panel.grid.minor = element_blank(), 
      axis.line = element_line(colour = "red", size=0.5),
      legend.position="none")+coord_equal(1) + theme_classic()
print(C) 

Solution

  • You are overwriting your custom theme settings when you add +theme_classic() after your custom theme. Instead, try

    C <- B + theme_classic() + theme(
          text = element_text(size = 20, face='bold'),
          panel.background = element_blank(),
          panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(), 
          axis.line = element_line(colour = "red", size=0.5),
          legend.position="none")+coord_equal(1)
    

    You may also consider to add aspect.ratio = 1 to your theme()-call, instead of coord_equal(1).