/
98-basic-scatterplot-matrix.html
479 lines (454 loc) · 16.7 KB
/
98-basic-scatterplot-matrix.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!doctype html>
<html lang="en">
<head>
<!-- Google Analytics + AdThrive -->
<!-- AdThrive Head Tag Manual -->
<script data-no-optimize="1" data-cfasync="false">
(function (w, d) {
w.adthrive = w.adthrive || {};
w.adthrive.cmd = w.adthrive.cmd || [];
w.adthrive.plugin = "adthrive-ads-manual";
w.adthrive.host = "ads.adthrive.com";
var s = d.createElement("script");
s.async = true;
s.referrerpolicy = "no-referrer-when-downgrade";
s.src =
"https://" +
w.adthrive.host +
"/sites/6434363fc11d8059e61106b4/ads.min.js?referrer=" +
w.encodeURIComponent(w.location.href) +
"&cb=" +
(Math.floor(Math.random() * 100) + 1);
var n = d.getElementsByTagName("script")[0];
n.parentNode.insertBefore(s, n);
})(window, document);
</script>
<!-- End of AdThrive Head Tag -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=UA-79254642-1"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "UA-79254642-1");
</script>
<!-- Google Analytics + OutboundLink + Google Adsense -->
<meta charset="utf-8" />
<title>Basic scatterplot matrix – the R Graph Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta
name="description"
content="This post explains how to build a scatterplot matrix with base R, without any packages. It provides several reproducible examples with explanation and R code."
/>
<meta
name="keywords"
content="R,ggplot2,tidyverse,Example,Data,Dataviz,Datavisualization,Plot,Chart,Graph,Learning,Caveat,Pitfall,Mistake"
/>
<meta name="author" content="Yan Holtz" />
<link rel="icon" href="img/logo/R_single_small.png" />
<!-- Control appearance when shared by social media -->
<meta property="og:title" content="Basic scatterplot matrix" />
<meta
property="og:image"
content="https://www.r-graph-gallery.com/img/overview_RGG.png"
/>
<meta
property="og:description"
content="This post explains how to build a scatterplot matrix with base R, without any packages. It provides several reproducible examples with explanation and R code."
/>
<meta
property="og:url"
content="https://www.r-graph-gallery.com/98-basic-scatterplot-matrix.html"
/>
<meta property="og:type" content="website" />
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<!-- Custom fonts for this template -->
<link
href="vendor/font-awesome/css/font-awesome.min.css"
rel="stylesheet"
type="text/css"
/>
<!-- Custom styles for this template -->
<link href="css/agency.css" rel="stylesheet" />
<!-- JQUERY -->
<script src="vendor/jquery/jquery.min.js"></script>
</head>
<body data-spy="scroll" data-target="#myScrollspy" data-offset="1">
<!-- THIS ALLOWS TO INSERT THE MENU THAT IS STORED IN A MENU.HTML FILE-->
<nav class="navbar navbar-expand-lg fixed-top" id="mainNav"></nav>
<script>
$(function () {
$("#mainNav").load("html_chunk/menu.html");
});
</script>
<!-- THIS ALLOWS TO INSERT THE MODAL OF THE MENU THAT IS STORED IN A MENU_MODAL.HTML FILE-->
<div id="modal_menu_insertion"></div>
<script>
$(function () {
$("#modal_menu_insertion").load("html_chunk/menu_modal.html");
});
</script>
<div id="modal_subscribe_insertion"></div>
<script>
$(function () {
$("#modal_subscribe_insertion").load("html_chunk/subscribe_modal.html");
});
</script>
<!-- Header = Title in big + social media Icon + quick description -->
<header class="masthead" style="padding-bottom: 30px">
<div class="textlanding">
<center><h1>Basic scatterplot matrix</h1></center>
<hr class="short_hr" />
<br />
<ul class="list-inline social-buttons">
<li class="list-inline-item">
<a href="https://twitter.com/R_Graph_Gallery">
<i class="fa fa-twitter"></i>
</a>
</li>
<li class="list-inline-item social-buttons">
<a href="https://github.com/holtzy">
<i class="fa fa-github" style="color: white"></i>
</a>
</li>
<li class="list-inline-item social-buttons">
<a href="https://www.linkedin.com/in/yan-holtz-2477534a/">
<i class="fa fa-linkedin"></i>
</a>
</li>
<li class="list-inline-item social-buttons">
<a href="https://www.yan-holtz.com">
<i class="fa fa-home"></i>
</a>
</li>
</ul>
<center>
<p style="max-width: 600px; margin-top: 40px">
This post explains how to build a
<a href="correlogram.html">scatterplot matrix</a> with base R,
without any packages. It provides several reproducible examples with
explanation and R code.
</p>
</center>
<div style="text-align: center">
<a
class="btn btn-secondary btn-xl text-uppercase js-scroll-trigger"
href="correlogram.html"
>Correlogram section</a
>
<a
class="btn btn-secondary btn-xl text-uppercase js-scroll-trigger"
href="https://www.data-to-viz.com/graph/correlogram.html"
>Data to Viz</a
>
</div>
</div>
</header>
<!-- THIS ALLOWS TO INSERT THE ADVERTISEMENT BANNER THAT IS STORED IN A BANNER.HTML FILE-->
<div id="position_for_images"></div>
<script>
$(function () {
$("#position_for_images").load("html_chunk/images.html");
});
</script>
<!-- STYLE for chart pages but not the rest of tthe website -->
<style>
img {
margin-top: 20px;
}
</style>
<div class="container">
<h1 id="scatterplot-matrix-with-the-native-plot-function">
Scatterplot matrix with the native <code>plot()</code> function
</h1>
<hr />
<div class="row">
<div class="col-md-6 col-sm-12 align-self-center">
<p>
For a set of data variables (dimensions) X1, X2, ??? , Xk, the
scatter plot matrix shows all the pairwise
<a href="scatterplot.html">scatterplots</a> of the variables on a
single view with multiple scatterplots in a matrix format.
</p>
<p>
The native <code>plot()</code> function does the job pretty well as
long as you just need to display scatterplots. For more option,
check the <a href="correlogram.html">correlogram section</a>
</p>
</div>
<div class="col-md-6 col-sm-12">
<p>
<img
src="98-basic-scatterplot-matrix_files/figure-html/thecode-1.png"
width="100%"
/>
</p>
</div>
</div>
<div class="sourceCode" id="cb1">
<pre
class="sourceCode r"
><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="co"># Data: numeric variables of the native mtcars dataset</span></a>
<a class="sourceLine" id="cb1-2" data-line-number="2">data <-<span class="st"> </span>mtcars[ , <span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">3</span><span class="op">:</span><span class="dv">6</span>)]</a>
<a class="sourceLine" id="cb1-3" data-line-number="3"> </a>
<a class="sourceLine" id="cb1-4" data-line-number="4"><span class="co"># Plot</span></a>
<a class="sourceLine" id="cb1-5" data-line-number="5"><span class="kw">plot</span>(data , <span class="dt">pch=</span><span class="dv">20</span> , <span class="dt">cex=</span><span class="fl">1.5</span> , <span class="dt">col=</span><span class="st">"#69b3a2"</span>)</a></code></pre>
</div>
<!-- Close container -->
</div>
<!-- ============================ RELATED SECTION ============================ -->
<section
class="bg-light"
id="portfolio_landing"
style="padding-top: 30px; padding-bottom: 30px; margin-top: 100px"
>
<div class="container">
<p class="mySeryTitle">Related chart types</p>
<hr />
<div class="row">
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="scatterplot.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img
class="img-fluid"
src="img/section/ScatterPlot150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Scatter</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="heatmap.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img class="img-fluid" src="img/section/Heatmap150.png" alt="" />
</a>
<div class="captionPortfolio">Heatmap</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="correlogram.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img
class="img-fluid"
src="img/section/Correlogram150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Correlogram</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="bubble-chart.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img
class="img-fluid"
src="img/section/BubblePlot150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Bubble</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="connected-scatterplot.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img
class="img-fluid"
src="img/section/ScatterConnected150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Connected scatter</div>
</div>
<div
class="col-md-2 col-sm-4 portfolio-item show column correlation numonly bigdata"
>
<a class="portfolio-link" href="2d-density-chart.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img
class="img-fluid"
src="img/section/2dDensity150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Density 2d</div>
</div>
</div>
</div>
</section>
<!-- ============================ CONTACT SECTION ============================ -->
<section
id="contact"
class="bg"
style="background-color: white; padding-top: 60px"
>
<div class="container">
<div class="row">
<div class="col-lg-2 text-center"></div>
<div class="col-lg-8 text-center">
<br /><br /><br />
<h2 class="section-heading text-uppercase" style="color: black">
Contact
</h2>
<p>
This document is a work by
<a href="https://www.yan-holtz.com">Yan Holtz</a>. Any feedback is
highly encouraged. You can fill an issue on
<a href="https://github.com/holtzy/D3-graph-gallery/issues"
>Github</a
>, drop me a message on
<a href="https://twitter.com/R_Graph_Gallery">Twitter</a>, or send
an email pasting <a href="">yan.holtz.data</a> with
<a href="">gmail.com</a>.
</p>
<div style="text-align: center">
<a
class="btn btn-primary btn-xl text-uppercase js-scroll-trigger"
href="https://github.com/holtzy"
>Github</a
>
<a
class="btn btn-primary btn-xl text-uppercase js-scroll-trigger"
href="https://twitter.com/R_Graph_Gallery"
>Twitter</a
>
</div>
</div>
</div>
</div>
</section>
<!-- ============================ FOOTER SECTION ============================ -->
<!-- AdThrive Footer Code Start-->
<script
type="text/javascript"
async
src="https://btloader.com/tag?o=5698917485248512&upapi=true&domain=r-graph-gallery.com"
></script>
<script>
!(function () {
"use strict";
var e;
(e = document),
(function () {
var t, n;
function r() {
var t = e.createElement("script");
(t.src =
"https://cafemedia-com.videoplayerhub.com/galleryplayer.js"),
e.head.appendChild(t);
}
function a() {
var t = e.cookie.match("(^|[^;]+)\s*__adblocker\s*=\s*([^;]+)");
return t && t.pop();
}
function c() {
clearInterval(n);
}
return {
init: function () {
var e;
"true" === (t = a())
? r()
: ((e = 0),
(n = setInterval(function () {
(100 !== e && "false" !== t) || c(),
"true" === t && (r(), c()),
(t = a()),
e++;
}, 50)));
},
};
})().init();
})();
</script>
<!-- AdThrive Footer Code End -->
<footer class="bg-light" id="myFooter">
<div class="container">
<div class="row">
<div class="col-md-4">
<span class="copyright"
>Copyright © the R graph gallery 2018</span
>
</div>
<div class="col-md-4">
<ul class="list-inline social-buttons">
<li class="list-inline-item">
<a href="https://twitter.com/R_Graph_Gallery">
<i class="fa fa-twitter"></i>
</a>
</li>
<li class="list-inline-item">
<a href="https://github.com/holtzy">
<i class="fa fa-github"></i>
</a>
</li>
<li class="list-inline-item">
<a href="https://www.linkedin.com/in/yan-holtz-2477534a/">
<i class="fa fa-linkedin"></i>
</a>
</li>
</ul>
</div>
<div class="col-md-4">
<ul class="list-inline quicklinks">
<li class="list-inline-item">
<a href="#">Privacy Policy</a>
</li>
<li class="list-inline-item">
<a href="#">Terms of Use</a>
</li>
</ul>
</div>
</div>
</div>
</footer>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$("tr.header")
.parent("thead")
.parent("table")
.addClass("table table-condensed");
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- ============================ JAVASCRIPT SECTION ============================ -->
<!-- Bootstrap core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Custom scripts for this template -->
<script src="js/agency.min.js"></script>
</body>
</html>