Search code examples
rggbiplot

ggbiplot removal of background


Hi I have made a ggbiplot with the example given in the package. I would like to know if it's possible to remove the grey background.

library(ggbiplot)

data(wine)

wine.pca <- prcomp(wine, scale. = TRUE)

print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE))

I have looked into the functions given here

https://github.com/vqv/ggbiplot/blob/master/R/ggbiplot.r

But as far as I can see none of these parameteres changes the background.

I am not experienced in R, but if someone has a solution for the wine example I am sure I can extrapolate to my own data.

Thank you very much!


Solution

  • There are multiple options, but all of them include changing the "theme" somehow. It doesn't has anything to do with biplot, with with ggplot itself.

    First, change only the background:

    + theme(panel.background = element_blank())
    

    If you want to remove the grid lines as well:

    + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
    

    Further options are in ?theme

    Second, you can change the total theme, for example:

    + theme_bw()  #black and white theme, as previously suggested
    + theme_classic(à  # classic theme
    

    Or of course, you can combine both.

    You can find further info here: http://felixfan.github.io/rstudy/2013/11/27/ggplot2-remove-grid-background-margin/