campbio/musicatk

Is It Possible To Have Connections Between Samples in UMAPs

Closed this issue · 2 comments

Hi,

I am working with pre-treatment and post-treatment data, and I was wondering if it would be possible to add a connectivity variable into the plot_umap function so that I could highlight where a pre-treatment and post-treatment samples fall in the umap amongst all the other samples in my umap. I have posted an example below

image

Compared to the original UMAP
Screenshot 2023-06-06 at 12 32 09 PM

Hi @kevlumbus,
We do not currently have that option in the plot_umap function. However, I believe it would be straightforward to get the umap coordinates out of the musica object and make a plot yourself. Here is how you get the UMAP info out:

umap.coord <- umap(result)

You can then add the treatment and pair info to a data.frame and create a plot yourself according to this documentation:

https://datavizpyr.com/connect-paired-points-with-lines-in-scatterplot-in-ggplot2/

Something like:

library(ggplot2)
umap.coord <- umap(result)
df <- data.frame(umap.coord, timepoint=timepoint, paired = paired)
df %>%
  ggplot(aes(UMAP_1,UMAP_2, color=timepiont)) +
  geom_point() +
  geom_line(aes(group = paired),color="grey")

Just let us know if you have more questions.