在vegan :: ordispider中更改网络的颜色

时间:2020-11-04 20:44:58

标签: r vegan

我正在尝试绘制PCoA分析的结果。现在,我正在尝试使用R基本图,然后也许会转到ggplot2。

我的问题是我似乎无法在ordispider中更改蜘蛛的颜色。我可以更改这些点的颜色,但是我希望蜘蛛将它们匹配以提高绘图的易懂性。

这就是我得到的:

library(vegan)
opar <- par(no.readonly = TRUE)

# Import data
alevines <- read.csv("Alevins_2020_ANALYSISFINAL.csv")

# Data transformation
dens <- subset(alevines, select = Dsar:Sym)
dens_rt4 <- dens^(1/4)

# Bray-Curtis distance matrix
bray_rt4 <- vegdist(dens_rt4, method = "bray")

# Tranformation of Bray-Curtis matrix to solve negative eigenvalues
sqrt <- sqrt(bray_rt4)
pcoa_sqrt <- cmdscale(sqrt, eig = TRUE)

# Extraction of points' coordinates to simplify
pcoa_final <- pcoa_sqrt$points

# Species information
spp_pcoa <- envfit(pcoa_final, dens)

# Plot
par(pty = "s")
plot(pcoa_final, asp = 1, type = "n",
     xlab = "PCoA 1", ylab = "PCoA 2",
     main = "PCoA Analysis \n Effect of the geographical zone on juvenile assemblages")
ordispider(pcoa_final, group = alevines$Zone, col = "grey", label = TRUE)
points(pcoa_final, pch = 21, bg = factor(alevines$Zone))
plot(spp_pcoa, col = "blue")

par(opar)

# Data that I used:
df <- cbind(alevines[, 3], as.data.frame(pcoa_final))

df #  where "alevines[, 3]"] is the variable Zone that is relevant for the plot (I get error if I try to change the name)

   alevines[, 3]          V1          V2
1          N_FRA -0.31953966 -0.13211577
2          N_FRA -0.34125036 -0.14192262
3          N_FRA -0.10213578 -0.32434163
4          N_FRA -0.06270165 -0.32624418
5          N_FRA  0.16412846 -0.10339652
6          S_FRA  0.10157215 -0.07840044
7          S_FRA  0.01062563 -0.06712275
8          S_FRA -0.09468745  0.05534594
9          S_FRA  0.21076827 -0.06278015
10         S_FRA  0.04307528 -0.13179782
11         S_FRA -0.07427778  0.17044107
12         S_FRA -0.05814288  0.15888828
13         S_FRA -0.23892210 -0.15302405
14         S_FRA  0.02524980 -0.36828943
15         S_FRA -0.11896887  0.18927065
16         S_FRA -0.22328449  0.12771682
17         S_FRA -0.09757700  0.08558142
18         S_FRA -0.04772112  0.18979261
19         S_FRA  0.08473274 -0.19854426
20         S_FRA -0.11273182  0.02583739
21         S_FRA -0.10407023  0.18530682
22         S_FRA  0.03202366  0.05072311
23         N_ESP -0.01593828  0.19298540
24         N_ESP -0.16013361  0.06503471
25         N_ESP  0.08506459 -0.10828077
26         N_ESP  0.02226936  0.02115659
27         N_ESP  0.26005384  0.08631482
28         N_ESP  0.10542508 -0.08439371
29         N_ESP  0.26768177  0.07939082
30         N_ESP  0.26699288  0.01749142
31         N_ESP  0.18508141 -0.20541575
32         N_ESP  0.15115365  0.02252165
33         N_ESP -0.20182258  0.12868039
34         N_ESP  0.03325551 -0.11145528
35         N_ESP -0.13561777  0.19630368
36         N_ESP -0.19252249  0.13937554
37         N_ESP -0.20645713  0.01362222
38         N_ESP  0.02491676 -0.15700943
39         S_ESP  0.25340805  0.14671086
40         S_ESP  0.13124834  0.16250687
41         S_ESP  0.21613607  0.12191268
42         S_ESP  0.23363973  0.12162282

我试图像这样在ordispider中替换col:

ordispider(pcoa_final, group = alevines$Zone, factor(alevines$Zone), label = TRUE)

但是我让所有蜘蛛变成绿色,这不是我想要的:( 如何将蜘蛛的颜色从灰色更改为分配给这些点的相同颜色? 我希望我能提供足够的信息:)

1 个答案:

答案 0 :(得分:0)

请注意,如果参数的位置不正确,则必须命名。 ordispider的第三个参数是display,这确实不了解如何处理factor(alevines$Zone)。 color的参数称为col。它应该与匹配,而不是与得分匹配。因此,它应该是组长度的向量。对于三组,参数col = 1:3应该设置标准调色板中三组的颜色。

相关问题