PCOA Visualization

I am preparing a PCoA analysis graph and having a hard time setting the scales for the PC1 and PC2. The numbers on the axis are shown to the 6 digits and in a continuous level which is unnecessary. Here is the code that I am using.. First by selecting a certain column and then visualizing for PC1 and PC2

data_pcoa_membrane <- filter(data_pcoa_scores, stream == "Membrane")

ggplot(data_pcoa_membrane, aes(PC1, PC2, colour = year, shape = year)) +
geom_point() +
coord_fixed() +
theme_bw()

@paleolimbot, what do you think ?

I wonder if you're having trouble with continuous vs. discrete variables and ggplot2 complaining that the year variable is continuous? Perhaps something like:

library(tidyverse)

# Sample data, randomly generated here, but you probably read from a file
data_pcoa_scores <- tibble(
  stream = "Membrane",
  PC1 = runif(10),
  PC2 = runif(10),
  year = rep(c(2021L, 2022L), each = 5)
) |> 
  # The 'year' variable has to be a factor(), or else ggplot2 thinks that
  # it is a continuous variable instead of a discrete one!
  mutate(
    year = as_factor(year)
  )

data_pcoa_membrane <- data_pcoa_scores |> 
  filter(stream == "Membrane")
 
ggplot(data_pcoa_membrane, aes(PC1, PC2, colour = year, shape = year)) +
  geom_point() +
  coord_fixed() +
  theme_bw()

Created on 2023-10-30 with reprex v2.0.2

...would do the trick?

(You may have to include a bit more detail in your question, like the error message, or some made-up sample data, or some output that you didn't expect to get more useful answers :slight_smile: )

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.