颜色未显示在散点图上

时间:2020-02-13 16:20:27

标签: r genome rda

我正在尝试进行RDA分析,为此,我必须使用我的SNP(散点图上的点)创建一个图。我为点分配了颜色,但是一旦绘制它们,就不会填充它们,而是用灰色勾勒出白色圆圈。 附件是我的代码,附件是我所得到的图像以及所要显示的图像。还随附了一个较小数据集的图像,以使您更容易查看我在做什么!预先谢谢你!

#gen1 Dataset
 POP   L0001 L0002 L0003
   <chr> <dbl> <dbl> <dbl>
 1 AK        0     1     0
 2 NU       -1    -1    -1
 3 GR        1     0     0
 4 LB        0     1     0
 5 NF        1     0     0
 6 ST        0     0     0
 7 NS       -1     2     0
 8 NB        1     2     0
 9 ME        0     1     0
10 IC        0     0     0
11 FI        0     0     0

#env1 dataset
POP   CHLa.max CHLa.min CHLa.avg
   <chr>    <dbl>    <dbl>    <dbl>
 1 AK       2.07    0.0623    0.780
 2 NU       0.943   0.0697    0.245
 3 GR       2.03    0.0494    0.453
 4 LB       1.55    0.263     0.678
 5 NF       1.63    0.190     0.698
 6 ST       2.40    1.17      1.74 
 7 NS       1.14    0.0708    0.447
 8 NB       1.79    0.231     0.900
 9 ME       1.69    0.131     0.711
10 IC       2.28    0.147     0.892
11 FI       0.554   0.0569    0.207

#Specify columns
gen1<-gen1[2:4]

#Specify predictors
pred1<-subset(env1[,1])

#Conduct RDA
BLGU.rda <- rda(gen1 ~ ., data=pred1, scale=T)
BLGU.rda

#Define Populations
levels(env1[["POP"]]) <- c("AK", "NU", "GR", "LB", "NF", "ST", "NS", "NB", "ME", "IC", "FI")

#Give Populations Callback Name
eco1 <- env1[["POP"]]

#Assign Colours
bg <- c("#fa8a6b", "#5d7142", "#010c22", "#61cd9e", "#7110b6", "#15c4df", "#892f74", "#0615f3", "#b6faea", "#e402b1", "#ad4833")

#Plot RDA
plot(BLGU.rda, type="n", scaling=2)

#Plot populations
points(BLGU.rda, display="sites", pch=21, cex=1.3, col="gray32", scaling=2, bg=bg[eco])

env1 Data

gen1 Data

RDA的散点图(SNP与环境预测因子

我希望数据看起来像的散点图

1 个答案:

答案 0 :(得分:0)

如果我正确理解,您想要做的就是在rda上绘制数据点,并根据一列为它们着色。

您的数据(需要一段时间才能读取):

env1 <- structure(list(POP = structure(c(1L, 10L, 3L, 5L, 8L, 11L, 9L, 
7L, 6L, 4L, 2L), .Label = c("AK", "FI", "GR", "IC", "LB", "ME", 
"NB", "NF", "NS", "NU", "ST"), class = "factor"), CHLa.max = c(2.07, 
0.943, 2.03, 1.55, 1.63, 2.4, 1.14, 1.79, 1.69, 2.28, 0.554), 
    CHLa.min = c(0.0623, 0.0697, 0.0494, 0.263, 0.19, 1.17, 0.0708, 
    0.231, 0.131, 0.147, 0.0569), CHLa.avg = c(0.78, 0.245, 0.453, 
    0.678, 0.698, 1.74, 0.447, 0.9, 0.711, 0.892, 0.207)), class = "data.frame", row.names = c(NA, 
-11L))

gen1 <- structure(list(POP = structure(c(1L, 10L, 3L, 5L, 8L, 11L, 9L, 
7L, 6L, 4L, 2L), .Label = c("AK", "FI", "GR", "IC", "LB", "ME", 
"NB", "NF", "NS", "NU", "ST"), class = "factor"), L0001 = c(0L, 
-1L, 1L, 0L, 1L, 0L, -1L, 1L, 0L, 0L, 0L), L0002 = c(1L, -1L, 
0L, 1L, 0L, 0L, 2L, 2L, 1L, 0L, 0L), L0003 = c(0L, -1L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-11L))

rda步骤和图解,请在下次包含库:

library(vegen)
BLGU.rda <- rda(gen1[,-1] ~ as.matrix(env1[,-1]), scale=T)

#Assign Colours
bg <- c("#fa8a6b", "#5d7142", "#010c22", "#61cd9e", "#7110b6", "#15c4df", "#892f74", "#0615f3", "#b6faea", "#e402b1", "#ad4833")
names(bg) <- c("AK", "NU", "GR", "LB", "NF", "ST", "NS", "NB", "ME", "IC", "FI")

plot(BLGU.rda, type="n", scaling=2)
points(BLGU.rda, display="sites", pch=21, cex=1.3, col="gray32", scaling=2, bg=bg[as.character(env1$POP)])
legend("topright",fill=bg,names(bg),ncol=3)

enter image description here