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

legend missing for color="variable" in plot_ordination #1325

Closed imanamoeba closed 4 years ago

imanamoeba commented 4 years ago

Hi there, I have been drawing some PCoA plots in phyloseq v 1.30.0 and can't get the legend for the 'color' variable to appear. The legend appears fine for the shape= "variable" (more info below). Does anyone have any suggestions as to why this may be?

Many thanks in advance, Bonnie

#Check structure and associated variables for phyloseq object d
d
phyloseq-class experiment-level object
otu_table()   OTU Table:         [ 3915 taxa and 131 samples ]
sample_data() Sample Data:       [ 131 samples by 7 sample variables ]
tax_table()   Taxonomy Table:    [ 3915 taxa by 7 taxonomic ranks ]
phy_tree()    Phylogenetic Tree: [ 3915 tips and 685 internal nodes ]

sample_variables(d)
[1] "Individual"      "Time"            "Treatment"       "Enclosure"      
[5] "Sex"             "Extraction.date" "Library.batch"  

#plot pcoa
p14 <- plot_ordination(d, d_Jaccard_pcoa, type="samples", color="Treatment", shape="Time") + 
  geom_point(size=5) + scale_colour_hue(guide = FALSE) 

image

As you can see in the plot, the treatments are plotted in different colours, as desired, but no legend for the colours appear. No matter which of my variables I attribute to 'color' and 'shape', the 'color' variable does not appear in the legend, whilst the 'shape' one does. This also holds true when only 'color' is specified and 'shape'=NULL.

imanamoeba commented 4 years ago

I've realised that omitting the scale_colour_hue(guide = FALSE) argument in the plot_ordination() command solves this issue- my fault for not paying close enough attention to what each argument does >,<