3

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))
raumkundschafter
  • 429
  • 1
  • 8
  • 24

1 Answers1

4

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.

admccurdy
  • 694
  • 3
  • 11
  • Just one little issue becomes apparent when I use custom colors. e.g. `group.colors <- c(barolo = "#c4019a", grignolino = "#9ac401", barbera ="#019ac4")` and then `g <- ggbiplotmod(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE) + scale_colour_manual(values=group.colors, name = '')` `print(g)` results in printing two sets of groups in the legend right of the plot. One featuring the three groups in black and white with the different line types and the other three underneath with just the different colors. – raumkundschafter Mar 05 '16 at 17:22
  • ggplot2 legends are great except when they're not...at least that's my experience. I've had legends that don't look exactly the way I'd like them to and its always a bit of a journey to get what I want. I don't do it often enough and usually have to search around SO to find out how to do specifically what I want. This might be helpful in your case http://stackoverflow.com/questions/12410908/combine-legends-for-color-and-shape-into-a-single-legend. You might need to make changes inside the function again. – admccurdy Mar 05 '16 at 18:00