<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/easily-add-images-to-a-correspondence-analysis-plot-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.displayr.com/easily-add-images-to-a-correspondence-analysis-plot-in-r/"> R – Displayr</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img sizes="(max-width: 300px) 100vw, 300px" alt="correspondence analysis" class="webfeedsFeaturedVisual wp-post-image" src="https://i2.wp.com/www.displayr.com/wp-content/uploads/2017/05/correspondence-logos-scaled-300x185.png?resize=300%2C185&ssl=1" data-recalc-dims="1">
<p><img sizes="(max-width: 780px) 100vw, 780px" alt="" class="wp-image-1697" src="https://i2.wp.com/www.displayr.com/wp-content/uploads/2017/05/CorrespondenceAnalysisLogo.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>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.</p>
<p>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.</p>
<hr>
<p> </p>
<h1><span>Step 1: Installing the packages</span></h1>
<p>The first step is to install the <span>flipDimensionReduction</span> 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.</p>
<pre> 
install.packages(&quot;devtools&quot;)
library(devtools)
install_github(&quot;Displayr/flipChartBasics&quot;)
install_github(&quot;Displayr/flipData&quot;)
install_github(&quot;Displayr/flipDimensionReduction&quot;)
install_github(&quot;Displayr/flipExampleData&quot;)
install_github(&quot;Displayr/flipFormat&quot;)
install_github(&quot;Displayr/flipImputation&quot;)
install_github(&quot;Displayr/flipPlots&quot;)
install_github(&quot;Displayr/flipStatistics&quot;)
install_github(&quot;Displayr/flipTransformations&quot;)
install.packages(&quot;GPArotation&quot;)
install.packages(&quot;plotly&quot;)
install.packages(&quot;psych&quot;)
install_github(&quot;Displayr/rhtmlLabeledScatter&quot;)
install_github(&quot;Displayr/rhtmlMoonPlot&quot;)
</pre>
<hr>
<pre></pre>
<h1><span>Step 2: Create the images</span></h1>
<p>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.</p>
<p> </p>
<hr>
<p> </p>
<h1><span>Step 3: Create a data table</span></h1>
<p>The main input to the correspondence analysis is a table of data. I have used data from the <span>flipExampleData</span> package, giving the table a name of <span>csd</span>.</p>
<pre>
data(csd.perceptions, package = &quot;flipExampleData&quot;)
csd = csd.perceptions * 100
</pre>
<hr>
<pre></pre>
<h1><span>Step 4: Use CorrespondenceAnalysis</span></h1>
<p>Next, we call the CorrespondenceAnalysis function. Here, we use the default arguments, other than telling it we want a <em>scatterplot</em>, and passing in the logos that we want to display:</p>
<pre>
library(flipDimensionReduction)
CorrespondenceAnalysis(csd,
 output = &quot;Scatterplot&quot;,
 logos = c(&quot;http://docs.displayr.com/images/9/90/Coke.png&quot;,
 &quot;http://docs.displayr.com/images/7/7c/V.jpg&quot;,
 &quot;http://docs.displayr.com/images/8/82/RedBull.jpg&quot;, 
 &quot;http://docs.displayr.com/images/d/dc/LifePlus.jpg&quot;,
 &quot;http://docs.displayr.com/images/0/09/DietCoke.png&quot;,
 &quot;http://docs.displayr.com/images/d/da/Fanta.jpg&quot;,
 &quot;http://docs.displayr.com/images/e/e8/Lift.png&quot;,
 &quot;http://docs.displayr.com/images/5/5e/Pepsi.jpg&quot;))
</pre>
<p>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.</p>
<p> </p>
<hr>
<p> </p>
<h1><span>Step 5: Rearrange any images using drag and drop</span></h1>
<p>The resulting visualization, shown below, is an <em>HTMLwidget</em>, and the underlying <span>d3</span> 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).</p>
<p>To play around with the R code for this post in Displayr, <a target="_blank" rel="nofollow" href="https://app.displayr.com/Try/Correspondence%20analysis%20logos">click here</a>.</p>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/212988/b0b579f4-5c15-4a05-b838-1439fc96bc8d.html?v=34784-3444062"></iframe></p>
<p><span>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.</span></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.displayr.com/easily-add-images-to-a-correspondence-analysis-plot-in-r/"> R – Displayr</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/14qldpzp0VA"></a></div>