# How to best display crosstab data?

I have a 10x10 matrix composed of two variables with 10 brands each. One variable is the brand purchased, the other is the brand considered. My matrix shows a crosstabulation between the two. I need an effective way to clearly visualize these data so that proximities suggest similarities between categories and distances dissimilarities. I ran a correspondence analysis, but wasn't impressed with the graph. Are there any alternative technique to consider?

• Can you say more about what was wrong / inadequate about the correspondence analysis? Apr 12 '13 at 4:50
• So the data are basically pairs of [brand considered, brand chosen]? If so then your crosstab is a transition matrix. That characterisation might help you find a nice visualisation. Apr 13 '13 at 16:57
• Following that line of thought you might look at how people visualise mobility tables in sociology (correspondence analysis and also 'association models' spring immediately to mind) Apr 13 '13 at 16:57

## 2 Answers

I'm not certain of your exact data, or the process you're using to analyze it, but what you describe makes me think of a correlation matrix. In R, generating the matrix, as well as the corresponding heat map (with dendrogram) is easy. The example below used example data to show correlations between usage rates of different IT applications, and generates the image using the "plots" and "RColorBrewer" packages in R.

Note that you do not need to pass a correlation matrix to the following script example; you may pass cross-tab results directly, as any numbers in the matrix will be translated into the heatmap.

Sample data:

,Service Catalog, Incident Management, CMDB, Platform, Change Management, Knowledge,
Request Management
Service Catalog,100,95,92,88,85,80,65
Incident Management,95,100,90,79,86,83,50
CMDB,92,90,100,68,85,76,42
Platform,88,79,68,100,79,61,45
Change Management,85,86,85,79,100,58,85
Knowledge,80,83,76,61,58,100,45
Request Management,65,50,42,45,85,45,100


Sample code:

MyData <- subset(Example, select=c(Service.Catalog:Request.Management))

MyMatrix <- as.matrix(MyData)
MyScaled <- scale(MyMatrix)

library("plots")

install.packages("RColorBrewer")

png(filename="MyTest.png", width = 500, height = 500, res=72)

heatmap.2(MyMatrix, margins=c(20,20))

heatmap(MyMatrix, margins=c(15,15))
dev.off()


• Is that a correlation matrix? The OP clearly asked to visualize a crosstabulation. I believe, though, theat map like yours is possible with it, too. The colours will tell of the cell residuals. Apr 12 '13 at 10:15
• The sample code provided does not require the input data be the result of a correlation matrix analysis, so any numerical data (e.g. averages, percentages, etc) will work. Apr 12 '13 at 12:35
• The key here to this display is to order the columns/rows so that not only is color useful in depicting whatever value (perhaps residuals as ttnphns mentions), but also that similar items are nearby in rows and columns. I presume a logical ordering can be derived from the correspondence analysis itself (although here it looks like the heatmap function has some default ordering not explicit in the code, but kind of identifiable from the attached hierarchical clustering dendrograms). Apr 12 '13 at 13:57

A two-way bar chart is often as effective as anything else. You have in effect a table of bars arranged in rows and columns. Length or height of bar encodes count or amount in cell, rather than colour of tile in a heat map.

The same kind of display comes under many names, including aligned bar charts, multi-pane bar charts, survey plots, table lens, Bertin plots, Hinton plots, Willshaw plots, and no doubt others.

A correspondence analysis can indicate good ordering of rows and columns; this problem is often called seriation.

See for example http://www.jstatsoft.org/v25/i03