<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Applying biplotEZ</title>
<link>https://muvisu.github.io/Applying-biplotEZ/applications.html</link>
<atom:link href="https://muvisu.github.io/Applying-biplotEZ/applications.xml" rel="self" type="application/rss+xml"/>
<description>Showcasing how the biplotEZ R package is applied to interesting data sets.</description>
<generator>quarto-1.8.24</generator>
<lastBuildDate>Tue, 22 Sep 2026 22:00:00 GMT</lastBuildDate>
<item>
  <title>When does Walmart sell? Weekly and yearly movements in 70 store departments</title>
  <dc:creator>Raeesa </dc:creator>
  <link>https://muvisu.github.io/Applying-biplotEZ/applications/walmart-sales/</link>
  <description><![CDATA[ 




<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>The <a href="https://www.kaggle.com/competitions/m5-forecasting-accuracy">M5 Forecasting Accuracy</a> data were released by Walmart for a forecasting competition hosted on Kaggle. They record the number of units sold, every day, for 3049 products in 10 stores across three US states: California (CA_1 to CA_4), Texas (TX_1 to TX_3) and Wisconsin (WI_1 to WI_3). The daily record runs for 1941 days, from 29 January 2011 to 22 May 2016.</p>
<p>Each product belongs to one of seven departments: three food departments (FOODS_1 to FOODS_3), two hobbies departments (HOBBIES_1 and HOBBIES_2) and two household departments (HOUSEHOLD_1 and HOUSEHOLD_2). A separate calendar table says which weekday and month each of the 1941 days falls on.</p>
<p>That is far too much for one picture: 30490 sales series of 1941 days each. A biplot needs a modest table of rows and columns, so the first job is to decide what a row should be and what a column should be.</p>
</section>
<section id="the-question" class="level2">
<h2 class="anchored" data-anchor-id="the-question">The question</h2>
<p>Shops have certain movements. Weekends are busier than weekdays and some goods sell in December that nobody buys in June. The question we ask is whether every part of Walmart shares the same movement or whether some stores and some departments march to their own beat. Specifically:</p>
<ul>
<li>Do the three states differ in <em>when</em> during the week they sell?</li>
<li>Do the seven departments differ in <em>when</em> during the year they sell?</li>
</ul>
</section>
<section id="preparing-the-data" class="level2">
<h2 class="anchored" data-anchor-id="preparing-the-data">Preparing the data</h2>
<p>We chose the <strong>store department</strong> as the row: one row for each of the 10 stores crossed with the 7 departments, giving 70 rows. Each row pools all the products in that department of that store.</p>
<p>For the columns we want a measure of movement, not of size. FOODS_3 sells more in a day than HOBBIES_2 sells in a month and if we used raw unit counts the picture would only show that food outsells hobbies. So for each store department we computed its average daily sales on, say, Saturday, and divided by its average daily sales across all days. A value of 1.2 means Saturdays run 20 percent above that store department’s own average and 0.8 means 20 percent below. Finally we took the logarithm, which makes “20 percent above” and “20 percent below” equally far from zero. These are the numbers the biplot axes are calibrated in.</p>
<p>This gives two tables with the same 70 rows:</p>
<ul>
<li>a <strong>weekday panel</strong> with 7 columns, Monday to Sunday, and</li>
<li>a <strong>month panel</strong> with 12 columns, January to December.</li>
</ul>
<p>Christmas Day was dropped before averaging because every store is closed and all sales are zero. The code below shows how the panels were built from the raw Kaggle files. It is not run on this page because the raw data are close to half a gigabyte, but the two finished panels are saved next to this post as small CSV files.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(data.table)</span>
<span id="cb1-2"></span>
<span id="cb1-3">sales <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fread</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/sales_train_evaluation.csv"</span>)</span>
<span id="cb1-4">cal   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fread</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/calendar.csv"</span>)</span>
<span id="cb1-5">cal[, date <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.IDate</span>(date)][, mday <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mday</span>(date)]</span>
<span id="cb1-6"></span>
<span id="cb1-7">id_cols  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"item_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dept_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cat_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"store_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"state_id"</span>)</span>
<span id="cb1-8">day_cols <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^d_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(sales), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reshape one store to long format (one row per product per day),</span></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># attach the calendar and drop Christmas Day</span></span>
<span id="cb1-12">long_store <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) {</span>
<span id="cb1-13">  l <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">melt</span>(sales[store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> s], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id.vars =</span> id_cols, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure.vars =</span> day_cols,</span>
<span id="cb1-14">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variable.name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value.name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"units"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variable.factor =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-15">  l <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cal[, .(d, weekday, month, mday)][l, on <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>]</span>
<span id="cb1-16">  l[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(month <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>L <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mday <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>L)]</span>
<span id="cb1-17">}</span>
<span id="cb1-18"></span>
<span id="cb1-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Total units (u) and number of product-days (n) per weekday and per month</span></span>
<span id="cb1-20">agg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(sales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>store_id)), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(s) {</span>
<span id="cb1-21">  l <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">long_store</span>(s)</span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd =</span> l[, .(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">u =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(units), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> .N), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> .(store_id, dept_id, weekday)],</span>
<span id="cb1-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mo =</span> l[, .(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">u =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(units), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> .N), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> .(store_id, dept_id, month)])</span>
<span id="cb1-24">})</span>
<span id="cb1-25">wd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(agg, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wd"</span>))</span>
<span id="cb1-26">mo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbindlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(agg, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mo"</span>))</span>
<span id="cb1-27"></span>
<span id="cb1-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log ratio of the weekday's (or month's) daily rate to the store</span></span>
<span id="cb1-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># department's overall daily rate</span></span>
<span id="cb1-30">to_panel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, key) {</span>
<span id="cb1-31">  base <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> x[, .(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(u) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n)), by <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .(store_id, dept_id)]</span>
<span id="cb1-32">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">merge</span>(x, base, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"store_id"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dept_id"</span>))</span>
<span id="cb1-33">  x[, z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>((u <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> m)]</span>
<span id="cb1-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dcast</span>(x, store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dept_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(key), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value.var =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span>)</span>
<span id="cb1-35">}</span>
<span id="cb1-36">weekday_panel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">to_panel</span>(wd, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"weekday"</span>)</span>
<span id="cb1-37">month_panel   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">to_panel</span>(mo, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"month"</span>)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Development version of biplotEZ, installed from GitHub with</span></span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   remotes::install_github("MuViSU/biplotEZ")</span></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(biplotEZ)</span>
<span id="cb2-4"></span>
<span id="cb2-5">weekday <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"weekday_panel.csv"</span>)</span>
<span id="cb2-6">month   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"month_panel.csv"</span>)</span>
<span id="cb2-7"></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The 7 (or 12) movement columns become the biplot variables</span></span>
<span id="cb2-9">W <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.matrix</span>(weekday[, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Monday"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tuesday"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Wednesday"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Thursday"</span>,</span>
<span id="cb2-10">                           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Friday"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saturday"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sunday"</span>)])</span>
<span id="cb2-11">M <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.matrix</span>(month[, month.abb])</span>
<span id="cb2-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(W) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(M) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(weekday<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>store_id, weekday<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dept_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":"</span>)</span>
<span id="cb2-13"></span>
<span id="cb2-14">state_cols <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CA =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2A6FD6"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TX =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3FAF3A"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">WI =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E8891C"</span>)</span></code></pre></div></div>
</details>
</div>
<p>The columns are already on a common scale (all are log ratios to the row’s own average), so the biplots below are centred but not standardised. Standardising would inflate the quiet months to the same importance as the busy ones, which is exactly the information we want to keep.</p>
</section>
<section id="the-weekly-movement" class="level2">
<h2 class="anchored" data-anchor-id="the-weekly-movement">The weekly movement</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biplot</span>(W, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">center =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scaled =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PCA</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group.aes =</span> weekday<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>state) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">samples</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> state_cols, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha.bags</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> state_cols) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ticks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://muvisu.github.io/Applying-biplotEZ/applications/walmart-sales/index_files/figure-html/weekday-state-1.png" class="img-fluid figure-img" width="768"></p>
<figcaption>PCA biplot of the weekday panel. Each point is one store department, coloured by state and each shaded region is an alpha bag enclosing the central 95 percent of its state’s points. The seven axes are the days of the week, calibrated in log ratios to the store department’s own average day.</figcaption>
</figure>
</div>
</div>
</div>
<p>This two-dimensional picture reproduces 92 percent of the variation in the seven-column table, so it is a good summary.</p>
<p><strong>Read the axes first.</strong> Saturday and Sunday point to the left and Monday to Thursday point to the right, with Friday pointing down between them. The tick marks on the Saturday axis reach 0.4 and beyond; a log ratio of 0.4 is about 50 percent above the store department’s average day. On the Tuesday to Thursday side the ticks are negative. So every store department sells more on the weekend, which is no surprise. The biplot is centred, so what the <em>spread</em> of points shows is how each store department departs from that shared pattern.</p>
<p><strong>The states do not have the same weekend.</strong> The Wisconsin bag sits low in the picture, pulled along the Saturday and Friday axes. The California bag stretches up and to the left, along the Sunday axis and Texas sits between them. Projecting the points onto the axes confirms it: in Wisconsin the Friday lift is positive and the Sunday lift is less than half of California’s, while California’s peak day is Sunday. In simple terms, Wisconsin’s weekend shopping starts on Friday and peaks on Saturday and California’s peaks on Sunday. Texas is in between.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biplot</span>(W, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">center =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scaled =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PCA</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group.aes =</span> weekday<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dept_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">samples</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha.bags</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ticks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://muvisu.github.io/Applying-biplotEZ/applications/walmart-sales/index_files/figure-html/weekday-dept-1.png" class="img-fluid figure-img" width="768"></p>
<figcaption>The same weekday biplot, now with the points coloured by department and one alpha bag per department.</figcaption>
</figure>
</div>
</div>
</div>
<p><strong>Departments differ less than states do.</strong> Colouring the same points by department gives bags that overlap much more, which says that <em>where</em> a department is matters more for its weekly movement than <em>what</em> it sells. Still, two departments stand out. HOBBIES_2 (magenta) hugs the right side of the picture near the weekday axes: its weekend lift is the smallest of any department, only around 10 percent above its average day. HOUSEHOLD_1 (black) reaches furthest to the left: household goods have the biggest weekend swing, with Saturdays around 25 percent above average and midweek days around 15 percent below. FOODS_2 (green) sits highest in the picture because its lift carries over into Monday, the only department for which Monday is an above-average day.</p>
</section>
<section id="the-yearly-movement" class="level2">
<h2 class="anchored" data-anchor-id="the-yearly-movement">The yearly movement</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biplot</span>(M, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">center =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scaled =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PCA</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group.aes =</span> month<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dept_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">samples</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha.bags</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ticks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://muvisu.github.io/Applying-biplotEZ/applications/walmart-sales/index_files/figure-html/month-dept-1.png" class="img-fluid figure-img" width="768"></p>
<figcaption>PCA biplot of the month panel. Points are the same 70 store departments, coloured by department with an alpha bag per department. The twelve axes are the months of the year, again calibrated in log ratios to the store department’s own average day.</figcaption>
</figure>
</div>
</div>
</div>
<p>The month picture explains 75 percent of the variation, less than the weekday picture and one glance shows why: most of that variation belongs to a single department.</p>
<p><strong>One department has a season.</strong> The HOBBIES_2 bag sits far to the left, alone, in the direction of the October, November and December axes and directly away from June and July. Reading off the calibrations, an average HOBBIES_2 department sells about 40 percent more per day in October than in a typical month and about 20 percent more in December, but roughly 20 to 25 percent less in June and July. The other six departments crowd together near the origin, which means their sales barely change from month to month. Whatever HOBBIES_2 contains, it is the seasonal, run-up-to-the-holidays part of the shop.</p>
<p><strong>Not every month is worth an axis.</strong> <code>biplotEZ</code> reports how well each axis is represented in the picture. October scores 0.98 and June to August all score above 0.85, so the picture reproduces those months well. May scores 0.01: the May axis is drawn but is essentially useless, because May is the one month in which nothing distinguishes one store department from another.</p>
<p><strong>A few individual outliers.</strong> Away from the HOBBIES_2 cluster, the point that strays furthest is FOODS_2 in store WI_1, up and to the left, away from the June to August axes and towards January. It sells about 20 percent more in January and 20 percent less in June to August than its average, a winter pattern that none of the other food departments share. TX_3’s FOODS_1 department shows a milder version of the same thing.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biplot</span>(M, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">center =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scaled =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PCA</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group.aes =</span> month<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>state) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">samples</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> state_cols, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha.bags</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> state_cols) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ticks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://muvisu.github.io/Applying-biplotEZ/applications/walmart-sales/index_files/figure-html/month-state-1.png" class="img-fluid figure-img" width="768"></p>
<figcaption>The month biplot coloured by state.</figcaption>
</figure>
</div>
</div>
</div>
<p><strong>Geography barely matters over the year.</strong> Coloured by state, the three bags lie almost on top of one another. Wisconsin’s bag reaches a little further towards February and March and a little less towards July, so its stores are slightly quieter in summer, but this is a small effect next to the weekday differences. The yearly movement is set by the goods on the shelf and the weekly movement by where the shelf stands.</p>
</section>
<section id="take-aways" class="level2">
<h2 class="anchored" data-anchor-id="take-aways">Take-aways</h2>
<ul>
<li>Everyone sells more on the weekend, but the states disagree on which day is the weekend: Saturday in Wisconsin, Sunday in California, with Texas in between.</li>
<li>What a department sells barely changes its weekly movement, except that household goods have the biggest weekend swing and HOBBIES_2 the smallest.</li>
<li>Over the year the roles reverse. The state makes almost no difference, while one department, HOBBIES_2, has a strong October to December season that no other department shares.</li>
<li>Expressing every cell as a log ratio to its own average is what made this possible. It removed the enormous differences in volume between departments and left only the shape of the movement, which is what the question was about.</li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Reproduce this post
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>This post uses the development version of biplotEZ from GitHub. Install it with <code>remotes::install_github("MuViSU/biplotEZ")</code> and <code>install.packages("geometry")</code> for the alpha bags, then run the code chunks above. The two panel files <code>weekday_panel.csv</code> and <code>month_panel.csv</code> sit next to this post. To rebuild them from the raw Kaggle data, download the M5 Forecasting Accuracy files from Kaggle into a <code>data/</code> folder and run the aggregation chunk, which needs the <code>data.table</code> package.</p>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>PCA</category>
  <category>retail</category>
  <category>time</category>
  <guid>https://muvisu.github.io/Applying-biplotEZ/applications/walmart-sales/</guid>
  <pubDate>Tue, 22 Sep 2026 22:00:00 GMT</pubDate>
</item>
<item>
  <title>What makes a red wine score well?</title>
  <dc:creator>Raeesa and Claude</dc:creator>
  <link>https://muvisu.github.io/Applying-biplotEZ/applications/wine-quality/</link>
  <description><![CDATA[ 




<section id="the-data" class="level2">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>The <a href="https://archive.ics.uci.edu/dataset/186/wine+quality">wine quality data set</a> was collected by Cortez and colleagues in 2009. It records eleven physicochemical measurements for 1 599 red <em>vinho verde</em> wines from the north of Portugal, such as acidity, sugar, alcohol and sulphur dioxide, together with a quality score from 0 to 10 awarded by a panel of tasters.</p>
<p>Each row is one wine. The eleven measurements are the variables we will draw as axes. The quality score is used only to colour the points, so we can see whether chemistry and taste agree.</p>
</section>
<section id="the-question" class="level2">
<h2 class="anchored" data-anchor-id="the-question">The question</h2>
<p>Wine chemistry is measured in a lab. Wine quality is judged by people. Do the wines that people like share a chemical profile, and if so, which measurements matter?</p>
</section>
<section id="the-biplot" class="level2">
<h2 class="anchored" data-anchor-id="the-biplot">The biplot</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Development version of biplotEZ, installed from GitHub with</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   remotes::install_github("MuViSU/biplotEZ")</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># It draws with ggplot2, so install.packages("ggplot2") if needed.</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(biplotEZ)</span>
<span id="cb1-5"></span>
<span id="cb1-6">wine <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"winequality-red.csv"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">";"</span>)</span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Group wines into three quality bands so the colouring is easy to read</span></span>
<span id="cb1-9">wine<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>band <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(wine<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>quality,</span>
<span id="cb1-10">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb1-11">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low (3-5)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Medium (6)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High (7-8)"</span>))</span>
<span id="cb1-12"></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Tidy the variable names for the plot</span></span>
<span id="cb1-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(wine) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">."</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(wine))</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the R code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biplot</span>(wine[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group.aes =</span> wine<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>band, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scaled =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PCA</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">samples</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E8891C"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2A6FD6"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3FAF3A"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opacity =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://muvisu.github.io/Applying-biplotEZ/applications/wine-quality/index_files/figure-html/biplot-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>PCA biplot of 1 599 red wines. Points are wines, coloured by quality band. Each labelled axis is one chemical measurement; a wine’s projection onto an axis approximates its value for that measurement.</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="what-the-picture-tells-us" class="level2">
<h2 class="anchored" data-anchor-id="what-the-picture-tells-us">What the picture tells us</h2>
<p>Because the eleven measurements are on very different scales (alcohol in percent, sulphur dioxide in milligrams per litre), each variable was standardised before the biplot was built. The plot then shows the two directions in which the wines vary most.</p>
<p><strong>Axes that point the same way measure the same thing.</strong> Fixed acidity and citric acid run almost parallel, and pH points the opposite way. That is the chemistry being explained: more acid means lower pH. Density and chlorides also travel together, pointing away from alcohol, because alcohol is lighter than water. Similarly, free and total sulphur dioxide point together because one is a component of the other.</p>
<p><strong>High-scoring wines sit on one side.</strong> The green points drift towards the alcohol axis and away from the volatile acidity axis. Volatile acidity is essentially vinegar, so wines with more of it score lower, while wines with more alcohol and more sulphates tend to score higher. The low-scoring orange points lean the other way.</p>
<p><strong>Chemistry only partly explains taste.</strong> The bands overlap heavily. Chemistry pushes a wine in a direction, but the tasting panel clearly responds to things the lab does not measure.</p>
</section>
<section id="take-aways" class="level2">
<h2 class="anchored" data-anchor-id="take-aways">Take-aways</h2>
<ul>
<li>Alcohol and sulphates are associated with higher scores; volatile acidity with lower scores.</li>
<li>Several measurements are near duplicates of each other, so the eleven variables carry far fewer than eleven separate pieces of information.</li>
<li>A biplot puts all of this in one picture: the groupings of wines, the relationships between measurements, and the link between the two.</li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Reproduce this post
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>This post uses the development version of biplotEZ from GitHub. Install it with <code>remotes::install_github("MuViSU/biplotEZ")</code>, then run the code chunks above. The data file <code>winequality-red.csv</code> sits next to this post and was downloaded from the UCI Machine Learning Repository.</p>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>PCA</category>
  <category>food and drink</category>
  <guid>https://muvisu.github.io/Applying-biplotEZ/applications/wine-quality/</guid>
  <pubDate>Tue, 15 Sep 2026 22:00:00 GMT</pubDate>
</item>
</channel>
</rss>
