Qiime2R PCOA with ggplot2

Hi. I have been following the Qiime2R tutorial with my dataset. I am trying to plot a PCOA with ggplot2, but i am running into several errors. My commands are:

metadata <- read_excel("metadata.xlsx")
table<-read_qza("table-no-mitochondria-no-chloroplast.qza")
taxonomy<-read_qza("taxonomy.qza")
faithpd<-read_qza("faith_pd_vector.qza")
pcoa<-read_qza("unweighted_unifrac_pcoa_results.qza")

pcoa$data$Vectors %>%
rename("#SampleID"=SampleID) %>% #rename to match the metadata table
left_join(metadata) %>%
left_join(faithpd$data %>% rownames_to_column("#SampleID")) %>%
ggplot(aes(x=PC1, y=PC2, shape=diet, color=host_order, size=faithpd)) +
geom_point() +
xlab(paste("PC1: ", round(100pcoa$data$ProportionExplained[1]), "%")) +
ylab(paste("PC2: ", round(100
pcoa$data$ProportionExplained[2]), "%")) +
theme_bw() +
ggtitle("Filtered Unweighted UniFrac")

But I received the errors:
Joining, by = "#SampleID"
Joining, by = "#SampleID"
Error: Aesthetics must be either length 1 or the same as the data (53): size
In addition: Warning message:
Column #SampleID joining factor and character vector, coercing into character vector

Below are the files which I've used:
unweighted_unifrac_pcoa_results.qza (146.2 KB) taxonomy.qza (262.3 KB) table-no-mitochondria-no-chloroplast.qza (421.9 KB) faith_pd_vector.qza (114.2 KB)

Metadata: muegge delsuc_mapping_file.txt (91.1 KB)

I have looked for solutions but still do not understand the errors to my case. I would appreciate any help with this, as I am still getting to know R.

Cheers!

2 Likes

I think the error is looking for something in ggplots and finding out that there's not enough (#53) to plot what you want to plot. In this case, it may be this:

color=host_order, size=faithpd

2 Likes

Hi Ben. Thanks for your help. According to my command lines, I am just looking to make the colors represent the few available host orders. And the faithpd of each plot to be mapped to size. I am still unsure about the issue preventing the plot.

As I also have 115 samples in my metadata, where did the '#53' come from?

I truly appreciate any clarification!

1 Like

It may be the # of different "host_orders" ranks? (looking at your mapping file it seems unlikely)

either way, it's something to do with your ggplots command. the aesthetics is expending 53 different values, but you're not providing these to ggplots. Try to just plot the individual points without the aesthetics (make it as basic as possible) then add back the aesthetics to find out what the issue may be. Ben