Qiime2R PCoA with ggplot metadata labels issue

Hi, I'm relatively new to Qiime2R and I've been attempting to produce a PCoA figure in R based off the 'Plotting PCoA' section in the tutorial (linked below). However, I've run into a problem in that the sub-labels aren't being differentiated resulting in this output:

My metadata is :
Pilot metadata 5.txt (939 Bytes)

And my code:

metadata5<-read_q2metadata("Pilot metadata 5.txt")
uwunifrac<-read_qza("unweighted_unifrac_pcoa_results.qza")
shannon<-read_qza("shannon_vector.qza")$data %>% rownames_to_column("SampleID")

uwunifrac$data$Vectors %>%
select(SampleID, PC1, PC2) %>%
left_join(metadata5) %>%
left_join(shannon) %>%
ggplot(aes(x=PC1, y=PC2, color='age-class', shape='sex', size=shannon_entropy)) +
geom_point(alpha=0.5) +
theme_q2r() +
scale_shape_manual(values=c(16,1), name="Sex") +
scale_size_continuous(name="Shannon Diversity") +
scale_color_discrete(name="Age-class")

I'm not sure why 'age class' and 'sex' are not being split as they are in the metadata. I've run the tutorial PCoA through and can reproduce that plot, and as far as I can tell my code is identical (except of course for the relevant filenames and metadata etc.) so I'm quite stuck.

Any help with this would be greatly appreciated!

1 Like

Hi @DrL ,

Welcome to the forum!

Would you mind sharing your unweighted_unifrac_pcoa_results.qza and shannon_vector.qza as well? You can PM me if you'd rather not share on the forum. It'll be much easier troubleshooting.

Also what version of qiime2R are you using?

2 Likes

Hi @Mehrbod_Estaki ,

Thank you very much for your response.

I can share them, but preferably as a PM if that's ok, is there a way to do that via the forum?

I'm using qiime2R version 0.99.6

1 Like

Try changing

...color='age-class', shape='sex'...

to

...color=`age-class`, shape=`sex`...

I believe it is trying to use the literal text for the aesthetic rather than the variable column. Be careful with copy and pasting as I think slack for example will sometimes convert ` to ' .

3 Likes

Hi @jbisanz ,

Amazing thank you, that's solved it!

1 Like