R dataframe join error: Can’t join on ‘#SampleID’ x ‘#SampleID’ because of incompatible types

Hi Jordan,

Thanks for the great tool and tutorial! I have been able to complete all steps in the tutorial before the phyloseq part except for making the final plot with beta and alpha diversity combined (the alpha diversity one works fine). For some reason, the SampleID’s in my beta diversity file seem to be characters instead of numeric. I am getting the error:

Error: Can’t join on ‘#SampleID’ x ‘#SampleID’ because of incompatible types (character / numeric)

When I use the code:

pcouw$data$Vectors %>%
rename("#SampleID"=SampleID) %>% #rename to match the metadata table
left_join(metadata_phylogeny) %>%
left_join(shannon_phylo$data %>% rownames_to_column("#SampleID")) %>%
ggplot(aes(x=PC1, y=PC2, shape=SubjectNumber, color=visitnumber, size=shannon)) +
geom_point() +
xlab(paste("PC1: ", round(100pcouw$data$ProportionExplained[1]), “%”)) +
ylab(paste("PC2: ", round(100
pcouw$data$ProportionExplained[2]), “%”)) +
theme_bw() +
ggtitle(“Unweighted UniFrac”)

Any ideas why this might be happening?

Thanks in advance!

This would suggest that you have named your samples using numbers only, which on a side note, can be problematic for a number of reasons. In the future I would recommend a unique alpha-numeric identifier both within a study, and between studies.

To bypass this issue you can manually coerce the sample ID to a character using:

yourobj %>% mutate(`#SampleID`=as.character(`#SampleID`))

I am not sure if it is your “pcouw$data$Vectors”, metadata, or “shannon_phylo$data”, which is creating this issue so you might need to add that command to each to find the issue.


Thanks so much for the quick reply, this worked!