1

I'm plotting two vectors with ggplot and want to color the resulting discrete points regarding their superpopulation tags (6 superpops in total, and using my personal color palette mypal). I have a data frame called newPC2 that has three columns: PC1 (x vector), PC2 (y vector), and Superpop (population tags, "EUR", "AMR"). When I try to do the following:

mypalette=c("blue","violetred1","green1","darkorchid1","yellow1","black")

ggplot(newPC2, aes(PC1, PC2, fill=Superpopulations2)) + 
  geom_point(size = 2.5) +
  scale_color_manual(values = mypalette) +
  theme(legend.position="bottom")

All the graph dots appear in black. I want the dots colored in one of 6 colors representing its superpopulations, to see how they distribute (they're PCA results).

Any thoughts? Thank you !

enter image description here

msimmer92
  • 397
  • 3
  • 16
  • 3
    The start of your `ggplot` call should be changed to `ggplot(newPC2, aes(PC1, PC2))` – Andrew Brēza Apr 24 '17 at 19:11
  • I'm sorry , I accidentally posted an old question. I already solved what you're answering, but now I've edited it with the question that I wanted to ask. Look again, please, and sorry! – msimmer92 Apr 24 '17 at 19:20
  • 1
    Change `fill` to `colour`. – www Apr 24 '17 at 19:24
  • 4
    You are using `scale_color_manual` but are setting the `fill=` aesthetic. `color` and `fill` are two different aesthetics. But it still seems odd they are all black. Sounds like you've mucked up your ggplot theme. Try running `theme_set(theme_grey())` to reset to default or if that doesn't work restart R. It's always a good idea to include a [reproducible example](http://stackoverflow.com/questions/5453840/how-can-i-change-the-default-theme-in-ggplot2) with sample input data so we can run and test what's going on. – MrFlick Apr 24 '17 at 19:24
  • 1
    Also consider adding `names` to your color palette to ensure consistent mapping. – Nate Apr 24 '17 at 19:25
  • With changing fill to colour as @ycw suggested, it worked perfectly ! thank you all :) . Still, I'm taking into account all your other comments to learn more about ggplot. Thank you ! (i'm a noob) – msimmer92 Apr 24 '17 at 19:26

1 Answers1

1

The default point geometry in ggplot is 16 (a dot) and so does not have a fill aesthetic, only a color. This means you will have to map the SuperPopulations2 variable onto color, ultimately with code that looks something like this:

ggplot(newPC2, aes(PC1, PC2, color=Superpopulations2)) + 
  geom_point(size = 2.5) +
  scale_color_manual(values = mypalette) +
  theme(legend.position="bottom")

This site has some pretty helpful information about using shapes.

m.evans
  • 606
  • 3
  • 15