We will use all the marginal gates of CD4+ for tsne

nodes <- getChildren(gs[[1]], "CD4+", path = 2)
nodes
## [1] "CD4+/IFNg"  "CD4+/IL2"   "CD4+/IL22"  "CD4+/IL4"   "CD4+/IL17a"
## [6] "CD4+/TNFa"

Firstly, create ggcyto object as usual (except omitting mapping here since it is always goingt to be x and y in tsne space)

p <- ggcyto(gs, subset = "CD4+") 
p <-  p + facet_grid(known_response~Peptide)

stat_tsne layer

Then add stat_tsne layer to ggcyto object

p <- p + stat_tsne(nodes = nodes, nEvents = 2e3, groupBy = "Peptide")

Note that here we can subsample nEvents from each sample to speed up tsen run At this point, tsne won’t be evalued until the inital plotting is requested.

geom_tsne_poly layer

Here we first plot the polyfunctional tsne plots.

p + geom_tsne_poly(degree = 3, count = 60)

#p + geom_point(aes(color = poly), data = function(x) x[degree >3,])

Keep in mind that the first plot can take some time due to the tsne computation.

geom_tsne_degree layer

But the subsequent plots will be fast since ggcyto will simply fetch the cached tsne data directly from ggcyto object. Here we can see the degree of functionality plot

p + geom_tsne_degree()

# p <- p + scale_color_gradientn(colours = rev(RColorBrewer::brewer.pal(11, "Spectral")))
# p + geom_point(aes(color = degree))

geom_tsne_marker layer

And we can also plot any marginal marker’s signal in tsne space

p + geom_tsne_marker("IL2")

p + geom_tsne_marker("IFNg")

# p <- p + scale_color_gradientn(colours = rev(RColorBrewer::brewer.pal(11, "Spectral")), trans = "log10")
# p + geom_point(aes(color = IFNg), size = 1.5, alpha = 0.5)
# p + geom_point(aes(color = IL2), size = 1.5, alpha = 0.5)