如何根据R中的另一组来定位不同颜色的点?

问题描述 投票:0回答:1

我有一个数据集,其中不同的基因型经历了不同的测试条件。这些是在多个不同的队列中完成的。因此,我想制作一个点图,以区分不同的基因型。我还希望每个基因型组中的每个点都有一种颜色,代表它们来自哪个同类群组。

我创建了一个数据集作为示例:

Y<-c(2,3,1,6,4,5,3,3,4)
X<-c('test','test','test','test','control','control','control','test','control')
Cohort <- c("first", "Second", "Second", "Second", "Second", "first", "Second","Second", "first")
Genotype<-c("WT","WT","WT","Mutant","Mutant","Mutant","Mutant","WT","WT")

DF<-data.frame(X,Y,Cohort,Genotype)
DF

ggplot(DF, aes(x=X, y=Y, group= X:Genotype)) +
  geom_dotplot(binaxis = "y", stackdir = "center", binwidth = 0.5, stroke= 3, aes(colour= Genotype, fill = Cohort), position = position_dodge(1)) +
  scale_fill_manual(values = c("light blue", "blue"))+
  scale_color_manual(values = c("orange",  "purple"))

执行此代码时,我得到一个类似于所需图形的图形。但是,有些点将留空,而不是根据同类群组进行着色。

Here is the graph with some dots unfilled.

谢谢您的帮助!

r ggplot2 grouping fill
1个回答
0
投票

也许您应该删除group中的aes。这里是一个例子:

ggplot(DF, aes(x = X, y = Y, fill = Cohort, color = Genotype))+
  geom_point(shape = 21, size = 10, position = position_jitter(0.2))+
  scale_fill_manual(values = c("light blue", "blue"))+
  scale_color_manual(values = c("orange",  "purple"))

enter image description here

它回答了您的问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.