View source: R/kmeans_join_DT.R
kmeans_join_DT | R Documentation |
data.table
Takes the results of K-means clustering performed by kmeans
and
joins them into a reference data table including the same samples.
kmeans_join_DT(refTab, sampCol = "SAMPLE", kFit)
refTab |
Data.table: the reference data.table with a column of sample
names, see param |
sampCol |
Character: a column in |
kFit |
Kmeans: an object produced by the function |
It is important that all the samples in refTab
match the names
of samples in kFit
. The function will throw a warning if this is not
the case, but will force the join regardless.
library(genomalicious)
data(data_Genos)
data_Genos
# Perform PCA.
PCA <- pca_genos(data_Genos)
# Get a table of PC axes
pcTable <- pca2DT(PCA)
# K-means clustering
K4 <- kmeans(PCA$x[,1:4], centers=4, nstart=10)
K4$cluster
# Add in inferred populations.
pcTable2 <- kmeans_join_DT(pcTable, 'SAMPLE', K4)
pcTable2
# Plot
(ggplot(pcTable2, aes(x=PC1, y=PC2, colour=CLUSTER))
+ geom_point()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.