---
layout: post
title: "Plotting principal coordinate axis 1 vs diversity in ggplot2"
blurb: "Blending community structure analyses with other data"
author: "PD Schloss"
date: 2021-04-02 09:30
comments: false
youtube: vJiK9d1wkTI
---

<iframe style="margin: 0 auto;display:block;" width="560" height="315" src="https://www.youtube.com/embed/{{ page.youtube }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>


## Code

This is where we started before the episode

```R
library(tidyverse)
library(readxl)
library(ggtext)
library(glue)

pcoa <- read_tsv(file="raw_data/schubert.braycurtis.pcoa.axes")

metadata <- read_excel(path="raw_data/schubert.metadata.xlsx", na="NA")

alpha_diversity <- read_tsv("raw_data/schubert.groups.ave-std.summary") %>%
  filter(method == "ave") %>%
  select(-label, -method)

metadata_pcoa_alpha <- inner_join(metadata, pcoa, by=c('sample_id'='group')) %>%
  mutate(disease_stat = factor(disease_stat,
                               levels=c("DiarrhealControl",
                                        "Case",
                                        "NonDiarrhealControl")
                               )
         ) %>%
  inner_join(., alpha_diversity, by=c("sample_id"="group"))


explained <- read_tsv("raw_data/schubert.braycurtis.pcoa.loadings")
explained1 <- explained %>% filter(axis==1) %>% pull(loading) %>% round(1)
explained2 <- explained %>% filter(axis==2) %>% pull(loading) %>% round(1)

healthy_color <- "#BEBEBE"
diarrhea_color <- "#0000FF"
case_color <- "#FF0000"
```

## Installations

* [See video](https://www.youtube.com/watch?v=D6CunpqF04E) for instructions on getting set up
* [R](https://r-project.org)
* [RStudio](https://rstudio.com)
* [Raw data](https://github.com/riffomonas/raw_data/releases/latest)
