# Data visualization from hierarchical clustering

I have data from questionnaire from school. 35 questions are various questions (influence of friends etc.)

Possible answers for 35 questions are "definitely yes", "mostly yes", "mostly no" and "definitely no".

I did hierarchical clustering using hclust in R. Then I used cutree for cut the dendrogram.

How to visualize data about clusters from cutree? I wrote function for export information about clusters to CSV, but I want to display graphical information.

Thanks

-
Is this a question of "How I plot the tree in R?" or "How do I visualize clustering, in general?" ? – StasK Mar 5 '13 at 20:11

There is a research tool called Hierarcial Clustering Explorer that can give you some examples for ways to visualize the clustering, and you could even download and play with it yourself. It would do the clustering for you and draw the dendogram, which you could then interact with to group the highly similar columns.

-

This is the most straightforward way to do this:

# Ward Hierarchical Clustering
d <- dist(mydata, method = "euclidean") # distance matrix
fit <- hclust(d, method="ward")
plot(fit) # display dendogram
groups <- cutree(fit, k=5) # cut tree into 5 clusters
# draw dendogram with red borders around the 5 clusters
rect.hclust(fit, k=5, border="red")


-

I believe your data is measured on a Likert Scale which might give you some leads.

I think the simplest way to approach this is that you could have already made graphs to explore the data before you clustered it, and the output of cutree (cluster number for each questionnairs) can be used to enhance these graphs.

For example, in the lattice package, using xyplot, you can specify things like (making up data, perhaps you have it, perhaps you don't):

xyplot (study.hours ~ age | cutree (h), data=surv)
xyplot (year ~ major | cutree (h), data=surv, jitter.x=TRUE, jitter.y=TRUE)
xyplot (year ~ major, groups=cutree (h), data=surv, jitter.x=TRUE, jitter.y=TRUE)
xyplot (happy ~ gym, groups=cutree (h), data=surv, jitter.x=TRUE, jitter.y=TRUE)


Etc. (In lattice, the vertical bar splits the graph up into multiple sub-graphs, while the groups= color-codes the points within the same graph.) The jitteris because I envision gym and happy as being answers to survey questions that are encoded on an integer scale of 1-4, and without jitter, you'd just get 16 places in the graph where points are all overplotted. Look at ?panel.xyplot to see variables like amount that allow you to jitter more or less.

You might also want to investigate the kohonen package, which implements SOM's, which are ways to get 2-D visualizations of multi-dimensional data. Might be better for your purposes than hclust.

-