joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
582 stars 187 forks source link

Changing legend labels in phyloseq (plot_ordination function) #1187

Open restivve opened 5 years ago

restivve commented 5 years ago

Hi,

I've plotted bray-cutis beta diversity (PCoA) and need to change the labels. I've done this for other plots in ggplot using a code like this:

relabunbray.ord$Site <- factor(relabunbray.ord$Site, levels=c("1_REF1", "2_REF2", "3_REF3", "4_DSW1", "5_DSW2", "6_DSW3", "7_DSK1", "8_DSK2", "9_DSK3", "10_DSK4"), labels=c("REF 1", "REF 2", "REF 3", "DSW 1", "DSW 2", "DSW 3", "DSK 1", "DSK 2", "DSK 3", "DSK 4"))

Unfortunately this doesn't work with the phyloseq function plot_ordinate.

I'm looking for a way to change the labels of the sites on the legend, please advise!

BrayCurtis_ChangeLegendLabels.pdf !

cabraham03 commented 5 years ago

I made the changes in the phyloseq object

Check the order of the metadata (example: "Description" column)

sample_data(PHY_OBJ)$Description

[1] "B7" "B16" "B40" "B35"

then change the names: sample_data(PHY_OBJ)$Description <- c("newname-7", "newname-16", "newname-40", "newname-35")

And the make the plot, analyses, etc, with the new label !!!!

I hope it help !!!

restivve commented 5 years ago

Hi,

Thank you for the help! When I did sample_data(phy_obj)$Site (site is what I want to re-label and order), I get the sites in order for each of the samples (so they are listed many times, more than just my 10 sites). If I continue with your code, it errors because its trying to relabel the first 10 samples (because I have 10 sites), but I have 150 samples and I don't want to have to copy this 150 times. Is there an easier way?

Victoria