I'm trying to make a hierarchical clustering tree from the clustering produced by Seurat's clustering function. Their functions, BuildClusterTree and PlotClusterTree, produce a frankly ugly tree based on SNN (shared nearest neighbor) algorithm that you can't manipulate with ggplot2. I'm trying to figure out how to use other functions to plot the clustering already produced by Seurat, but I can't figure out how or what R package would work best. Does anyone have any advice for me?
I would suggest the clustree package for this purpose
Related
I would like to visualize the workflow of a large function in diagram form using R, I used a package called flow for this purpose, but the given diagram is so blurred and totally unreadable.
Here's a simple example for visualizing the function of interest:
remotes::install_github("moodymudskipper/flow")
library(flow)
library(bvarsv)
data(usmacro)
flow_run(bvar.sv.tvp(usmacro))
Is there any way to improve the visualization and makes it more clear? I also would like to know if there are better methods to visualize the workflows of large functions in R.
Has anyone made a manual syntax of hierarchical clustering or ward clustering without the function (hclust() or agnes()) that found in packages ('cluster') in R?
If you have, can you share it?
Thanks a lot for the help
I currently have an adjacency matrix I would like to perform spectral clustering on to determine the community each node belongs to. I have looked around, but there do not look to be implementations in either igraph or other packages.
Another issue is determining how many clusters you want. I was wondering if R has any packages that might help one find the optimal number of clusters to break an adjacency matrix into? Thanks.
I cannot advise for R, however, I can suggest this example implementation of Spectral Clustering using Python and Networkx (which is comparable to iGraph). It should not be hard to translate this into R.
For an introduction to Spectral Clustering see lectures 28-34 here and this paper.
I am currently testing various community detection algorithms in the igraph package to compare against my implementation.
I am able to run the algorithms on different graphs but I was wondering if there was a way for me to write the clustering to a file, where all nodes in one community are written to one line and so on. I am able to obtain the membership of each node using membership(communities_object) and write that to a file using dput() but I don't know how to write it the way I want.
This is the first time I am working with R as well. I apologize if this has been asked before.
This does not have to do much with igraph, the clustering is given by a simple numeric vector. See ?write.
write(membership(communities_object), file="myfile", ncolumns=1)
write(communities_object$membership, file="myfile", ncolumns=1) also work
I am interested in using the pvclust R package to determine significance of clusters that I have generated using the regular hierarchical clustering hclust function in R. I have a datamatrix that consists of ~ 8000 genes and their expression values at 4 developmental time points. The code below shows what I use to perform regular hierarchical clustering on my data. My first question is: Is there a way to take hr.dendrogram plot and apply that to pvclust?
Secondly, pvclust seems to cluster columns, and it seems more appropriate for data that is being compared across columns rather than rows like I want to do (I have seen many examples where pvclust is used to cluster samples rather than genes). Has anyone used pvclust in a similar fashion to what I want to do?
My simple code for regular hierarchical clustering is as follows:
mydata<-read.table("Developmental.genes",header=TRUE, row.names=1)
mydata<-na.omit(mydata)
data.corr <-cor(t(mydata),method="pearson")
d<-as.dist(1-data.corr)
hr<-hclust(d,method="complete",members=NULL)
hr.dendrogram.<-plot(as.dendrogram(hr))
I appreciate any help with this!
Why not just use pvclust first like fit<-pvclust(distance.matrix, method.hclust="ward", nboot=1000, method.dist="eucl"). After that fit$hclust will be equal to hclust(distance.matrix).