Commit fbf37dea authored by Bernd Klaus's avatar Bernd Klaus

finished MDS section, t-SNE is next

parent 99d19446
......@@ -35,6 +35,7 @@ library("psych")
library("vsn")
library("matrixStats")
library("pheatmap")
library("MASS")
theme_set(theme_gray(base_size = 18))
......@@ -421,6 +422,76 @@ pheatmap(create_dist_mat(cleaned_data,
trace="none", col = rev(hmcol))
## ----scalingSingleCell---------------------------------------------------
tcell_log_counts <- as.data.frame(
read_csv("http://www-huber.embl.de/users/klaus/nbt.3102-S7.csv"))
rownames(tcell_log_counts) <- tcell_log_counts$X1
tcell_log_counts$X1 <- NULL
tcell_log_counts <- as.matrix(tcell_log_counts)
tcell_log_counts[1:5, 1:5]
dist_tcells <- get_dist(tcell_log_counts, method = "manhattan")
scaling_tcells <- as_tibble(cmdscale(dist_tcells, k = 2))
colnames(scaling_tcells) <- c("MDS_dimension_1", "MDS_dimension_2")
scaling_tcells <- add_column(scaling_tcells, cell_id = labels(dist_tcells),
.before = "MDS_dimension_1")
## ----plotScalingSingleCell, dependson="scalingSingleCell"----------------
gata3_idx <- which( "Gata3" == colnames(tcell_log_counts))
gata3_idx
gata3_exp <- tcell_log_counts[, gata3_idx]
gata3_group <- cut(gata3_exp,
breaks = quantile(gata3_exp, probs = seq(0, 1, 0.2)),
labels = c("very low", "low", "medium", "high", 'very high'),
include.lowest = TRUE)
scaling_tcells <- add_column(scaling_tcells, gata3_group, .after = "cell_id")
mds_plot_tcells <- ggplot(scaling_tcells, aes(x = MDS_dimension_1,
MDS_dimension_2,
color = fct_rev(gata3_group))) +
geom_point(size = 3) +
ggtitle("Metric MDS of the T-cell single cell data") +
scale_color_brewer(palette = "RdBu", direction = 1) +
coord_equal()
mds_plot_tcells
## ----checkScaling--------------------------------------------------------
dist_tcells_mds <- get_dist(select(scaling_tcells,
MDS_dimension_1, MDS_dimension_2),
method = "euclidean")
data_dist <- tibble(org_distance = as.vector(dist_tcells),
mds_distance = as.vector(dist_tcells_mds))
ggplot(data_dist, aes(x = org_distance, y = mds_distance)) +
geom_hex(binwidth = 100) +
geom_smooth(color = "grey10") +
scale_fill_distiller(palette = "YlOrRd", direction = 1) +
ggtitle(label = "Shepard plot",
subtitle = "Original vs MDS distances") +
coord_equal()
## ----ex_sheppard_plot----------------------------------------------------
ggplot(data_dist, aes(x = org_distance, y = mds_distance)) +
stat_density2d(aes(fill = ..level..), geom = "polygon",
n = 100, h = c(200, 200)) +
geom_smooth(color = "grey10") +
scale_fill_distiller(palette = "YlGn", direction = 1) +
ggtitle(label = "Shepard plot",
subtitle = "Original vs MDS distances") +
coord_equal()
## ----session_info, cache = FALSE-----------------------------------------
sessionInfo()
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment