NMDS plot output not matching the dataframe

30 views Asked by At

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 enter image description here

`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")`
1

There are 1 answers

2
andrea On

To use column values as the colour try scale_colour_identity() instead!