Search code examples
rggplot2pcaellipseggbiplot

How to change the line type of ellipses in ggbiplot?


Is it possible to change the type of lines of the normal probability ellipsoids in ggbiplot, e.g. have them dashed and dotted lines instead of or additional to the different colors? I couldn't find anything in the documentation of ggbiplot except this to be used as MWE:

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))

Solution

  • To the best of my knowledge it isn't possible with any or the arguments passed to ggbiplot. Luckily ggbiplot is a pretty simple wrapper for some ggplot2 commands and data massaging. You can copy the source code make a custom function and change line 124 of the original source from:

    g <- g + geom_path(data = ell, aes(color = groups, group = groups))

    to:

    g <- g + geom_path(data = ell, aes(color = groups, group = groups, linetype = groups))

    Because of the plot scale it's hard to tell the lines apart without changing the size outside of the aes() statement.