In R there is a way to display hierarchical clustering on a venn diagram

I am trying to display a hierarchical cluster in the form of a venn diagram or any other useful BESIDES dendrogram display. I want my data to be displayed in many different types of views.

Currently, the dendrogram will be built on this:

x <- hclust(dist(mtcars)) plot(x) 

What can I do to display a cluster diagram that LOOKS looks like this:

https://www.projectrhea.org/rhea/images/3/3b/Lecture23VennClusters_OldKiwi.jpg

or

http://bl.ocks.org/mbostock/7607535

or anything else that makes sense to display cluster data in this example.

It is advisable that this can be done in Shiny , but a simple example of R. is enough. Thank you in advance.

+5
source share
1 answer

The graphs you showed are cluster graphs. There are different ways to make these stories. Here is one approach. You can change the characters on or off, and fill in if you want. In addition, there are options for building dendrograms, i.e. here

 library(cluster) head(mtcars) fit <- kmeans(mtcars, 3) # 3 clusters aggregate(mtcars, by=list(fit$cluster), mean) newmtcars <- data.frame(mtcars, fit$cluster) head(newmtcars) # plot cluster solution library(cluster) clusplot(mtcars, fit$cluster, color=TRUE, shade=TRUE, lines=0) 

enter image description here

refs: http://www.statmethods.net/advstats/cluster.html https://stats.stackexchange.com/questions/31083/how-to-produce-a-pretty-plot-of-the-results-of -k-means-cluster-analysis

I'm not sure how the Venn diagram will differ from the above graph. Perhaps there should be overlapping groups. It depends on the data and the tree command. You can try changing the tree command, in this case kmeans, shows a little overlap when the number of iterations is selected.

 fit <- kmeans(mtcars, 3, iter.max = 2) # 3 clusters, low number of iterations clusplot(mtcars, fit$cluster, color=TRUE, shade=FALSE, lines=0) 

enter image description here

One way to do this with hierarchical clustering is to extract the groups from the tree and then use clusplot for the resulting groups.

 fit <- hclust(dist(mtcars)) groups <- cutree(fit, k=3) clusplot(mtcars, groups[rownames(mtcars)], color=TRUE, shade=FALSE, lines=0) 

To see how data segments with a large number of cuts in a tree, including a hierarchical tree, one approach is to use a cut, followed by clusplot

 heir_tree_fit <- hclust(dist(mtcars)) for (ncut in seq(1,10)) { group <- cutree(heir_tree_fit, k=ncut) clusplot(mtcars, group[rownames(mtcars)], color=TRUE, shade=FALSE, lines=0, main=paste(ncut,"cuts")) } 

Here are the numbers for 2, 6 and 10 abbreviations

enter image description here

enter image description here

enter image description here

You can make one chart with all abbreviations.

 par(new=FALSE) for (ncut in seq(1,10)) { group <- cutree(heir_tree_fit, k=ncut) clusplot(mtcars, group[rownames(mtcars)], color=TRUE, shade=FALSE, lines=0, xlim=c(-5,5),ylim=c(-5,5)) par(new=TRUE) } par(new=FALSE) 

enter image description here Another approach to creating a Venn hierarchical clustering diagram is to extract groups from a tree and then use vennDiagram in the resulting groups.

 # To make a Venn diagram # source("http://bioconductor.org/biocLite.R") biocLite("limma") library(limma) inGrp1 <- groups==1 inGrp2 <- groups==2 inGrp3 <- groups==3 vennData <- cbind(inGrp1, inGrp2, inGrp3) aVenn <- vennCounts(vennData) vennDiagram(aVenn) 

VennDiagramMTCAR

+1
source

Source: https://habr.com/ru/post/1205226/


All Articles