0

Given the following code using the ggbiplot library available via devtools::install.github() :

library(ggbiplot)
data(iris)
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]

ir.pca <- prcomp(log.ir, center = TRUE, scale. = TRUE)

g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, groups = ir.species)
g <- g + theme(legend.direction = 'vertical', legend.position = 'right')
g <- g + scale_color_manual(values=c("blue", "red", "green"))
print(g)

what is the best way to customize the border of the data points based on the grouping? I used scale_color_manual() to customize the color of those data points, but I can't think of a way to do that for the border.

Thanks

Julio Diaz
  • 9,067
  • 19
  • 55
  • 70

1 Answers1

0

Assuming you want to adjust the border of the data points themselves...

The ggbiplot() call itself won't give you this flexibility but setting alpha = 0 will make the points plotted by ggbiplot invisible or really 100% transparent. Then you can make a separate layer with a geom_point() call where you specify shape as one of the 5 shapes (21-25) that have a fill (the middle) and a color (the boarder) aesthetic.

ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, groups = ir.species, alpha = 0) +
    theme(legend.direction = 'vertical', legend.position = 'right') + 
    scale_color_manual(values=c("blue", "red", "green")) +
    scale_fill_manual(values = c("red", "green", "blue")) + # just offset by one to show
    geom_point(size = 3, shape = 21, aes(fill = groups, color = groups))

enter image description here

PS It's probably always a good idea to include in your question that the package you are using is only available via devtools::install.github() and not the standard install.packages()

Nate
  • 10,361
  • 3
  • 33
  • 40
  • Great Thanks!, I will change the original post and include the devtools information. – Julio Diaz Nov 03 '16 at 01:14
  • In this case how do you avoid the arrows drawn over? – Julio Diaz Nov 03 '16 at 01:27
  • good question, i don't know but i'm gonna play around with it – Nate Nov 03 '16 at 01:52
  • it looks like `ggbiplot()`'s default is to layer the points last, perhaps reduce size back to 1 to minimize arrow coverage or maybe use alpha or hollow shapes. sorry I can't give you a better answer – Nate Nov 03 '16 at 02:01