在 vegan::ordispider 内更改网页颜色
Change colour of the web in vegan::ordispider
我正在尝试绘制 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)
但是我把所有的蜘蛛都变成了绿色,这不是我想要的:(
如何将蜘蛛的颜色从灰色更改为分配给点的相同颜色?
我希望我提供了足够的信息:)
请注意,如果参数位置不正确,您必须注明参数名称。 ordispider
的第三个参数是display
,实在是不明白用factor(alevines$Zone)
干什么。颜色参数称为 col
。它应该匹配 groups – 而不是点。所以它应该是组长度的向量。对于三组,参数 col = 1:3
应从标准调色板设置三组的颜色。
我正在尝试绘制 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)
但是我把所有的蜘蛛都变成了绿色,这不是我想要的:( 如何将蜘蛛的颜色从灰色更改为分配给点的相同颜色? 我希望我提供了足够的信息:)
请注意,如果参数位置不正确,您必须注明参数名称。 ordispider
的第三个参数是display
,实在是不明白用factor(alevines$Zone)
干什么。颜色参数称为 col
。它应该匹配 groups – 而不是点。所以它应该是组长度的向量。对于三组,参数 col = 1:3
应从标准调色板设置三组的颜色。