msimmer92
msimmer92

Reputation: 397

Plotting discrete data regarding two color arguments

I did a principal component analysis and now I'm plotting the results in R (plotting the first versus the second principal components of 2514 individuals, and coloring all those points regarding 6 superpopulations to visualize the clusters). R default colors are nice, but I need that one superpopulation in particular stands out, so I want to color it black. I don't care about the colors of the other 5.

I'm having trouble to apply what I've read about customizing color palettes and plotting with ggplot. I tried to create a new palette, but I'm having trouble mixing the both things in the syntax. I have to tell the program (1) color every dot concerning it's Superpopulation information, and (2) use this new color palette, mypalette, but in the plotting syntax both infos have to be in the "col" argument, but I want to put two. Here's the code so far, which's not achieving what I want:

Superpopulations<-PC$Superpop
mypalette=c("blue","violetred1","green1","darkorchid1","yellow1","black")

mypal=discrete_scale(aesthetics = Superpulations, scale_name = "Superpopulations", palette = mypalette)

superpopulation<-qplot(newPC2$PC1,newPC2$PC2, col=mypal, main = NULL ,xlab= NULL, ylab=NULL, size=I(2.5))
superpopulation + theme(legend.position="bottom")

I also tried extracting only the URUS and using the command points() to plot them alone in black over the other points:

points(PCsurus2$PC1, PCsurus2$PC2, col="black")

But I don't see any changes in the plot.

PC is a data frame where the first two columns are principal component values 1 and 2, and other column is Superpop, with the name tags of the superpopulations (like "URU", "EUR"). And here I leave the graph. I want to change the URU colors from red to black to highlight that population

Upvotes: 0

Views: 64

Answers (1)

Axeman
Axeman

Reputation: 35382

I would advice against using qplot, it teaches you bad habits and does a poor job of exposing you to the principles behind the grammar. Here's what the ggplot() version would look like:

ggplot(newPC2, aes(PC1, PC2, Superpulation)) +            #Copied your misspelling(!)
  geom_point(size = 2.5) +
  scale_color_manual(values = mypal) +
  theme(legend.position="bottom")

Upvotes: 1

Related Questions