简体   繁体   English

绘制有关两个颜色参数的离散数据

[英]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中(将2514个人的第一主成分与第二主成分作图,并对与6个超种群有关的所有点进行着色以使群集可视化)。 R default colors are nice, but I need that one superpopulation in particular stands out, so I want to color it black. R默认颜色很好,但是我特别需要一个超级人群来突出显示,因此我想将其着色为黑色。 I don't care about the colors of the other 5. 我不在乎其他5。

I'm having trouble to apply what I've read about customizing color palettes and plotting with ggplot. 我在应用所学到的关于自定义调色板和使用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. 我必须告诉程序(1)为涉及其超级填充信息的每个点上色,以及(2)使用这个新的调色板mypalette,但是在绘图语法中,两个信息都必须在“ col”参数中,但是我想放两个。 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: 我还尝试仅提取URUS并使用命令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"). PC是一个数据帧,其中前两列是主成分值1和2,另一列是Superpop,带有超级人群的名称标签(例如“ URU”,“ EUR”)。 And here I leave the graph. 在这里,我离开图表。 I want to change the URU colors from red to black to highlight that population 我想将URU颜色从红色更改为黑色,以突出显示该人群

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. 我建议不要使用qplot ,它会教给您不良习惯,并且会使您无法qplot语法的原理。 Here's what the ggplot() version would look like: ggplot()版本如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM