Required Packages
#library(dplyr)
#require(graphics)
library(ggplot2)
library(ggfortify)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
#setting seed ensures PC1/2 values will be consistent across uses
set.seed(100)
Preparing the Distance Matrix
#set working directory
#replace the distance matrix file with either "Shh", "Sox2", or "Hoxb1Distancematrix.csv"
df <- read.csv("~/Desktop/bio321hw/ShhDistanceMatrix.csv") #Shh will be our example
#replace NA values with 0
df[is.na(df)] = 0
#Make species row names and remove unnecessary column with "X***"
df <- as.matrix(df[,-1])
row.names(df) <- colnames(df)
- At this point, the data format would be verified with “head” or “View()”
Using ggplot2 and ggfortify/plotly to generate PCoA
#run PCoA analysis with default parameters - "scale. = T" says the variables should be scaled
pcoa_Shh <- prcomp(df,scale. = T)
Shh <- autoplot(pcoa_Shh,shape = F, label = T,)
Shh + labs(title = "Shh PCoA Analysis")
