I have a data matrix as a .csv (output from sourmash). The matrix looks something like this: matrix
I also have metadata that corresponds with that matrix. It groups the samples represented in the matrix several different ways. It looks something like this: metadata
I'd like to plot an MDS while coloring certain points based on their metadata value. So far I've been able to upload the matrix and plot the points, but am lost on how to "link" the metadata values to the matrix so that I can color the matrix values by color when they are plotted. I know it's probably a simple fix but would appreciate any help! This is what I have so far:
#import matrix and metadata
sm_matrix <- read.csv("path to .csv", header = TRUE, sep = ",")
md <- read.csv("path to .csv", header = TRUE, sep = ",")
#transform for plotting
sm_matrix <- as.matrix(sm_matrix)
#plot
mds <- sm_test %>%
dist() %>%
cmdscale() %>%
as_tibble()
colnames(mds) <- c("dim.1", "dim.2")
I've also tried this to plot
ggscatter(mds, x = "dim.1", y = "dim.2",
color = md$Location,
palette = "jco",
size = 1,
ellipse = TRUE,
ellipse.type = "convex",
repel = TRUE)
but I get this error:
Error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data (92): colour
Run `rlang::last_error()` to see where the error occurred.
Warning message:
In if (color %in% names(data) & is.null(add.params$color)) add.params$color <- color :
the condition has length > 1 and only the first element will be used
Thank you!
Sam