## ----包括= false ---------------------------------------------------------------------------------------------------------- knitr::opts_chunk$set( error = FALSE, warning=FALSE, message=FALSE, collapse = TRUE, comment = "#>" ) library("BiocStyle“) ## - - 设置 - - - - - - - - - - - - - - - - - - - - -----------------------------------库(“ Snifter”)库(“ ggplot2”)theme_set(theme_bw())set.seed(42))n_obs <-500 n_feats <-200均值_1 <-rnorm(n_feats)neame_2 <-rnorm(n_feats)counts_a <- replicate(n_obs,rnorm(n_feats,neeme_1),neame_1))counts_b counts_b <-eb replicate(n_obs,n_obs,rnororm(n_obs rnororm(n_bems rnororm(rnorm renorm),)counts <-t(cbind(counts_a,counts_b))label < - rep(c(“ a”,“ b”),每个= n_obs)## ---------------------------------------------------------------------------------------------------------------- fit <-Fitsne(counts,Random_state = 42L)ggplot() + aes(fit [,1],fit [,2],color = label) + geom_point(pCH = 19)+ scale_colour_discrete(name =“ cluster”) +实验室(x =“ t-sne 1”,y =“ t-sne 2”)## ----拆分---------------------------------------------------------------------------------------------------------------------------------------------------------------------- test_ind < - 样本(nrow(counts), nrow(counts) / 2) train_ind <- setdiff(seq_len(nrow(counts)), test_ind) train_mat <- counts[train_ind, ] test_mat <- counts[test_ind, ] train_label <- label[train_ind] test_label < - label [test_ind]嵌入<-Fitsne(train_mat,andury_state = 42L)## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ new_coords <- project(embedding, new =test_mat,old = train_mat)ggplot() + geom_point(aes(embedding [,1],嵌入[,2],color = triar_label,shape =“ train”)) + geom_point(aes(ae new_coords [,1],new_coords,new_coords [new_coords [,2],color = test_label,shape =“ test”)) + scale_colour_discrete(name =“ cluster”) + scale_shape_discrete(name = null) + labs(x =“ t-sne 1”,y =“ t-sne t-sne 2)”)## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- sessionInfo()