NMDS 绘图输出与数据框不匹配

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

我正在尝试在 R 中绘制 NMDS 分数的排序图,但我注意到有关每个点的 point_color 和 point_shape 不匹配的问题。例如,站点 31 和 35 都属于组 1,并且在数据集中将是三角形且颜色为橙色。然而,该图将位点 31 输入为蓝色。这样做了几次,所以这似乎是颜色的问题。

`ggplot(terranmds.data_scorestest, aes(x = NMDS1, y = NMDS2)) +
  geom_point(aes(colour = factor(site), shape = factor(Group)), 
             size = 3, alpha = 0.7) +
  geom_text(aes(label = site, colour = factor(site)), vjust = 1.7, show.legend = FALSE) +
  labs(
    title = "Measured Communities Ordination Plot (August)",
    colour = "Year Communities",
    shape = "Temp. Grouping"
  ) +
  coord_equal() +
  scale_colour_manual(values = terranmds.data_scorestest$point_color, guide = "none") +  # Remove color legend +
  theme_classic() +
  theme(
    panel.background = element_rect(fill = NA, colour = "black", size = 1, linetype = "solid"),
    legend.position = c(0.05, 0.05),
    legend.justification = c(0, 0),
    legend.text = element_text(size = 12),
    legend.title = element_text(size = 12, face = "bold"),
    legend.box.background = element_rect(color = "black"),
    axis.text = element_text(size = 10),
    axis.title = element_text(size = 12, color = "grey14", face = "bold")
  ) +
  theme(plot.title = element_text(color = "#45ADA8", size = 15, face = "bold", hjust = 0.5)) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey") +
  geom_vline(xintercept = 0, linetype = "dashed", color = "grey")`

I am trying to plot an ordination plot for NMDS scores in R but I am noticing an issue regarding the point_color and point_shape are not matching for each point. For example site 31 and 35 are both Group 1, and will be triangles and colored orange in the dataset. However, the plot inputs site 31 as blue. It does that a few times so it seems to be an issue with the color. [![enter image description here][1]][1]
[![enter image description here][2]][2]


  [1]: https://i.stack.imgur.com/xRWYF.png
  [2]: https://i.stack.imgur.com/4JTQQ.png

`ggplot(terranmds.data_scorestest, aes(x = NMDS1, y = NMDS2)) +
  geom_point(aes(colour = factor(site), shape = factor(Group)), 
             size = 3, alpha = 0.7) +
  geom_text(aes(label = site, colour = factor(site)), vjust = 1.7, show.legend = FALSE) +
  labs(
    title = "Measured Communities Ordination Plot (August)",
    colour = "Year Communities",
    shape = "Temp. Grouping"
  ) +
  coord_equal() +
  scale_colour_manual(values = terranmds.data_scorestest$point_color, guide = "none") +  # Remove color legend +
  theme_classic() +
  theme(
    panel.background = element_rect(fill = NA, colour = "black", size = 1, linetype = "solid"),
    legend.position = c(0.05, 0.05),
    legend.justification = c(0, 0),
    legend.text = element_text(size = 12),
    legend.title = element_text(size = 12, face = "bold"),
    legend.box.background = element_rect(color = "black"),
    axis.text = element_text(size = 10),
    axis.title = element_text(size = 12, color = "grey14", face = "bold")
  ) +
  theme(plot.title = element_text(color = "#45ADA8", size = 15, face = "bold", hjust = 0.5)) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey") +
  geom_vline(xintercept = 0, linetype = "dashed", color = "grey")`
r ggplot2 vegan mds
1个回答
0
投票

要使用列值作为颜色,请尝试

scale_colour_identity()

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