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!

  • 1
    $\begingroup$ 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? $\endgroup$ – 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 enter image description here


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
clusplot(mydata, fit$cluster, color=TRUE, shade=TRUE, 
    labels=2, lines=0)

# Centroid Plot against 1st 2 discriminant functions
plotcluster(mydata, fit$cluster)

Which will produce this figure: enter image description here

  • $\begingroup$ Thanks.. it was helpful. For the last k-mean clustering, is there any other tool to make such cluster diagrams rather than R ? $\endgroup$ – Dark_Knight Oct 27 '16 at 11:58
  • 1
    $\begingroup$ 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). $\endgroup$ – hh32 Oct 27 '16 at 12:02
  • $\begingroup$ ok.. I also have to show this clustering on a country's map.. for that any tool? $\endgroup$ – Dark_Knight Oct 27 '16 at 12:04
  • $\begingroup$ 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. $\endgroup$ – hh32 Oct 27 '16 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.