david-barnett / microViz

R package for microbiome data visualization and statistics. Uses phyloseq, vegan and the tidyverse. Docker image available.
https://david-barnett.github.io/microViz/
GNU General Public License v3.0
106 stars 11 forks source link

Labelling samples in ord_plot PCoA #155

Closed we32i225 closed 5 months ago

we32i225 commented 5 months ago

Sorry if this has been asked before I am plotting a PCoA of my microbiome data using microviz's ord_plot function. Plots look great and easy to use. However, i would like to label each of the samples (circles and triangles) within the PCoA plot so i can see where each one falls. Is this possible and if so how? i have included a picture of my plot in its current state image

thanks!

david-barnett commented 5 months ago

Hi, do you mean label each individual point, or each colour/shape group?

If individual points, you should be able to add geom_text, or (maybe better geom_text_repel from ggrepel package) to the plot. set the label aesthetic e.g. geom_text_repel(aes(label = NAMEOFVARIABLEYOUWANTTOLABELWITH))

This will be pretty crowded though, so you might also want to filter the points you label, e.g. by setting the data argument to a filtering function in the geom to e.g. geom_text(data = function(df) filter(df, variable == "value"), mapping = aes(...))