In this tutorial, we will analyze single cell multi-dimensional rt-qpcr data from Guo et al. and share the results as HTML pages using canvasXpressR
.
library(canvasXpressR) ## Load rt-qpcr data from Guo et al. data(mat)
First, we will perform principal component analysis with k-means clustering and visualize the first and second PCs with a scatterplot.
## Principal components analysis with K means clustering set.seed(0) basePca <- prcomp(mat) data <- basePca$x[,1:2] sg <- kmeans(data, centers=3)$cluster sg[sg==1] <- 'TE'; sg[sg==2] <- 'PE'; sg[sg==3] <- 'EPI'; names(sg) <- rownames(data) varAnnot <- data.frame(sg) colnames(varAnnot) <- 'Cell Type' cx <- canvasXpress(data, varAnnot=varAnnot, graphType='Scatter2D', colorBy='Cell Type') write(canvasXpressHTML(cx), "pca.html")
We can now share the pca.html page directly to our collaborators for them to explore further. Note that all data are contained within this HTML page so you do not need to worry about uploading the data somewhere. Just open the HTML page and click to explore!
Next, we will plot a heatmap with cells as rows and genes as columns. We will keep the cell type groups we found from the PCA and visualize them as row side colors.
## Expression heatmap cmat <- t(mat) cx <- canvasXpress(cmat, smpAnnot=varAnnot, graphType='Heatmap', smpOverlays=list('Cell Type'), colorSpectrum=list("blue", "white", "red"), heatmapIndicatorHeight=50, heatmapIndicatorHistogram=TRUE, heatmapIndicatorPosition='topLeft', heatmapIndicatorWidth=60, samplesClustered=TRUE, variablesClustered=TRUE, showSampleNames=FALSE) write(canvasXpressHTML(cx), "heatmap.html")
We can now share the heatmap.html page directly to our collaborators for them to explore further. This is most helpful for collaborators to pick and choose which genes they want included in the final heatmap.
Now (my favorite utility), we will plot boxplots of each gene for each cell type.
## Boxplots cx <- canvasXpress(t(mat), smpAnnot=varAnnot, graphType='Boxplot', groupingFactors=list('Cell Type'), graphOrientation="vertical") write(canvasXpressHTML(cx, width=1200), "boxplot.html")
We can now share the boxplot.html page directly to our collaborators for them to explore further. Collaborators can interactively explore and visualize individual genes.
For networks and pseudo-time trajectories, we can plot a tree structure.
## Trajectories / Trees library(igraph) dis <- dist(mat[1:50,]) ## small tree g <- graph.adjacency(as.matrix(dis), weighted=TRUE) gmst <- mst(g) ## igraph object nodeData <- lapply(names(V(gmst)), function(x) list(name=x, id=x, group=sg[x])) edgeData <- apply(get.edgelist(gmst), 1, function(x) list(id1=x[1], id2=x[2])) cx <- canvasXpress(nodeData=nodeData, edgeData=edgeData, graphType="Network", colorNodeBy="group", nodeSize=30, showAnimation=TRUE) write(canvasXpressHTML(cx), "graph.html")
We can now share the graph.html page directly to our collaborators for them to explore further.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.