0

I am using ggbiplot() and would like to manipulate the colors and shapes of the datapoints to make them more printer friendly. Currently I get the default rainbow of colors from ggbiplot(). I have tried using the arguments "+ scale_colour_discrete" and "+ scale_shape_manual" but the "groups=" argument ggbiplot seems to override these. If I eliminate the "groups=" argument then ellipses can't be drawn. The "+ theme" argument works just fine. My code is below. I know I could manipulate the colors/shapes more easily in the regular biplot() function, but I like the confidence interval ellipses provided by ggbiplot().

g <- ggbiplot(size.pca, choices=1:2, obs.scale = 1, var.scale = 1,
       groups=fieldnames, ellipse = TRUE,ellipse.prob=0.68, varname.size=4) 

g <- g + scale_colour_discrete(name=" ") #only the name=" " part of this seems to work.

g <- g + scale_shape_manual(values=c(17,16,16,16,16,16), name= " ") #trying to indicate one population different from the rest, but it doesn't seem to do anything (no error either, just no change in the output).

g <- g + theme_bw() +theme(legend.direction = 'horizontal',
       legend.position = 'top') 

print(g)
Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
Sarah L
  • 1
  • 1
  • 1
  • 3
    It would be nice if you supplied some sample input data so we could see what your plot looks like and test possible solutions. See tips for including data in [how to create a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick May 06 '15 at 22:27
  • See this answer: http://stackoverflow.com/a/40305464/4477364 – Joe Oct 28 '16 at 13:15

1 Answers1

0

add a geom_point() argument to your ggplot script and the scale_color_manual to override the group default colour without changing the grouping vector like this:

g <- ggbiplot(size.pca, choices=1:2, obs.scale = 1, var.scale = 1,
       groups=fieldnames, ellipse = TRUE,ellipse.prob=0.68, varname.size=4) +
geom_point(aes(colour = fieldnames), size = "your size") +

scale_color_manual(values=c(17,16,16,16,16,16)) +

theme_bw() +theme(legend.direction = 'horizontal',
       legend.position = 'top') 

print(g)

This should work!

Luca T
  • 51
  • 1
  • 5