msimmer92
msimmer92

Reputation: 397

Coloring points regarding distinct groups in ggplot R

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

Upvotes: 1

Views: 721

Answers (1)

m.evans
m.evans

Reputation: 697

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.

Upvotes: 1

Related Questions