# How to draw a map of a cluster analysis results

I have performed k-mean clustering on a demographic data set. Now I wish to show the results on a (geographical) map, i.e. I want to show the clusters that I got after the analysis in a map. Can someone recommend me a platform (any free software or any online sources) where I can draw such a map?

PS - If this is the wrong stackexchange site to ask this question then please direct me to the correct one. Thank you!

• Our sister site GIS is devoted to all such platforms and their use. I don't recommend migrating your question there because it would likely be considered too broad and lacking in research. Why not investigate that site for a few minutes to see what options are out there? – whuber Oct 27 '16 at 14:58

A nice and popular method of viusalizing cluster analysis are dendrogramms. You can image it as a sort of tree like structure, that represents the linkage between clusters. It is defined by a metric (e.g. eucledian) and a clustering algorithm (e.g. ward).

Another way would to plot the data and colorize the points accoriding to their clustering. You could also colorize the backround in a similar way.

A good and free online resource would be "The R Programming Language". There are plenty tutorials to be found.

I'll try to give an short introduction, which i took from statmethods.net

# Prepate Data

# Prepare Data
mydata <- na.omit(mydata) # listwise deletion of missing
mydata <- scale(mydata) # standardize variables


# Cluster and Visualize

You can use a Dendrogramm to visualize a hierarchical clustering result like so:

# 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")


which will produce this image

# K-means

R provides also k-means clustering. The resulting clustering can also be shown like so:

# K-Means Clustering with 5 clusters
fit <- kmeans(mydata, 5)

# Cluster Plot against 1st 2 principal components

# vary parameters for most readable graph
library(cluster)
clusplot(mydata, fit$cluster, color=TRUE, shade=TRUE, labels=2, lines=0) # Centroid Plot against 1st 2 discriminant functions library(fpc) plotcluster(mydata, fit$cluster)


Which will produce this figure:

• Thanks.. it was helpful. For the last k-mean clustering, is there any other tool to make such cluster diagrams rather than R ? – Dark_Knight Oct 27 '16 at 11:58
• I'm not aware of any tool. But there are plenty of tool boxes, like caffe or scikitlearn for python. They're easy to use and you can plot the results. Or maybe have a look at octave (like matlab, but open source). – hh32 Oct 27 '16 at 12:02
• ok.. I also have to show this clustering on a country's map.. for that any tool? – Dark_Knight Oct 27 '16 at 12:04
• I don't know, but i don't think so. You'll have to plot the points manually, i.e. transform each point's position onto the map. – hh32 Oct 27 '16 at 12:08