1
votes

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

1
The start of your ggplot call should be changed to ggplot(newPC2, aes(PC1, PC2)) - Andrew Brēza
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
Change fill to colour. - www
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 with sample input data so we can run and test what's going on. - MrFlick
Also consider adding names to your color palette to ensure consistent mapping. - Nate

1 Answers

1
votes

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.