Categories
Research Technology (ResTech)
May 19, 2017
You can take your correspondence analysis plots to the next level by including images.
You can take your correspondence analysis plots to the next level by including images. Better still, you don’t need to paste in the images after the analysis is complete – you can include them right from the start.
The plot above shows the results of a correspondence analysis based on data from a study of how people perceive different carbonated soft drinks. Logos, which are from jpeg files, are shown instead of brand names, with lines and dots indicating the precise location of the brands. This post describes how to create this plot using R.
The first step is to install the flipDimensionReduction package and a series of dependent packages, which are listed below. Depending on how your R has been setup, you may need to install none of these (e.g., if using Displayr), or you may need to install more packages.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
install.packages ( "devtools" ) library (devtools) install_github ( "Displayr/flipChartBasics" ) install_github ( "Displayr/flipData" ) install_github ( "Displayr/flipDimensionReduction" ) install_github ( "Displayr/flipExampleData" ) install_github ( "Displayr/flipFormat" ) install_github ( "Displayr/flipImputation" ) install_github ( "Displayr/flipPlots" ) install_github ( "Displayr/flipStatistics" ) install_github ( "Displayr/flipTransformations" ) install.packages ( "GPArotation" ) install.packages ( "plotly" ) install.packages ( "psych" ) install_github ( "Displayr/rhtmlLabeledScatter" ) install_github ( "Displayr/rhtmlMoonPlot" ) |
The next step is to create some images of similar sizes and have the files hosted somewhere. The function that creates the correspondence analysis expects URLs rather than local files.
The main input to the correspondence analysis is a table of data. I have used data from the flipExampleData package, giving the table a name of csd.
1
2
|
data (csd.perceptions, package = "flipExampleData" ) csd = csd.perceptions * 100 |
Next, we call the CorrespondenceAnalysis function. Here, we use the default arguments, other than telling it we want a scatterplot, and passing in the logos that we want to display:
1
2
3
4
5
6
7
8
9
10
11
|
library (flipDimensionReduction) CorrespondenceAnalysis (csd, output = "Scatterplot" , |
If you check the help for this function, you will find parameters for lots of different types of customization, including resizing the logos, adding titles, etc.
The resulting visualization, shown below, is an HTMLwidget, and the underlying d3 code allows you to drag and drop to rearrange the images and other labels. If you use Displayr to publish the R code, the state will be remembered (i.e., it will remember where you have moved things to).
To play around with the R code for this post in Displayr, click here.
The example in this post displays correctly in normal desktop installations of R for Windows, but due to a bug in R Studio does not render in their browser.
Comments
Comments are moderated to ensure respect towards the author and to prevent spam or self-promotion. Your comment may be edited, rejected, or approved based on these criteria. By commenting, you accept these terms and take responsibility for your contributions.
Disclaimer
The views, opinions, data, and methodologies expressed above are those of the contributor(s) and do not necessarily reflect or represent the official policies, positions, or beliefs of Greenbook.
More from Tim Bock
Tim Bock on utilizing correspondence analysis.
Visualizations can summarize patterns that are commonly hidden in a simulator
Bad visuals stress the need for charts to be interpretable in seconds
Visualizing data can be made easier by utilizing small charts for comparison and analysis
Sign Up for
Updates
Get content that matters, written by top insights industry experts, delivered right to your inbox.
67k+ subscribers