-
Notifications
You must be signed in to change notification settings - Fork 23
/
02-moma.html
934 lines (862 loc) · 38.2 KB
/
02-moma.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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="Alison Hill" />
<title>Lab 02: MoMA Museum Tour</title>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/flatly.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/navigation-1.1/codefolding.js"></script>
<link href="site_libs/highlightjs-9.12.0/default.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 60px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 65px;
margin-top: -65px;
}
.section h2 {
padding-top: 65px;
margin-top: -65px;
}
.section h3 {
padding-top: 65px;
margin-top: -65px;
}
.section h4 {
padding-top: 65px;
margin-top: -65px;
}
.section h5 {
padding-top: 65px;
margin-top: -65px;
}
.section h6 {
padding-top: 65px;
margin-top: -65px;
}
</style>
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.parent().addClass('active');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
});
</script>
<div class="container-fluid main-container">
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<script>
$(document).ready(function () {
window.initializeCodeFolding("hide" === "show");
});
</script>
<script>
$(document).ready(function () {
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
padding-left: 25px;
text-indent: 0;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row-fluid">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">CS631 Labs</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="slides.html">Slides & Reading</a>
</li>
<li>
<a href="data-vis-resources.html">Resources</a>
</li>
<li>
<a href="https://sakai.ohsu.edu/portal/site/CS-631-1-32176-Sp18">Sakai</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="about.html">About</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<ul class="dropdown-menu" style="min-width: 50px;">
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
</ul>
</div>
<h1 class="title toc-ignore">Lab 02: MoMA Museum Tour</h1>
<h3 class="subtitle"><em>CS631</em></h3>
<h4 class="author"><em>Alison Hill</em></h4>
</div>
<div id="goals-for-lab-02" class="section level1">
<h1><span class="header-section-number">1</span> Goals for Lab 02</h1>
<ul>
<li>Review <code>dplyr</code> functions learned in last lab and DataCamp course</li>
<li>Practice using <code>dplyr</code> functions to get to know a new dataset</li>
<li>Map global plot aesthetics to variables in <code>ggplot2</code></li>
<li>Create facetted plots with <code>ggplot2</code></li>
</ul>
</div>
<div id="slides-for-today" class="section level1">
<h1><span class="header-section-number">2</span> Slides for today</h1>
<pre class="r"><code>knitr::include_url("slides/02-slides.html")</code></pre>
<iframe src="slides/02-slides.html" width="672" height="400px">
</iframe>
</div>
<div id="inspiration-data" class="section level1">
<h1><span class="header-section-number">3</span> Inspiration + data</h1>
<p>We’ll use data from the Museum of Modern Art (MoMA)</p>
<ul>
<li>Publicly available on <a href="https://github.com/MuseumofModernArt/collection">GitHub</a></li>
<li>As analyzed by <a href="https://fivethirtyeight.com/features/a-nerds-guide-to-the-2229-paintings-at-moma/">fivethirtyeight.com</a></li>
<li>And by <a href="https://medium.com/@foe/here-s-a-roundup-of-how-people-have-used-our-data-so-far-80862e4ce220">others</a></li>
</ul>
</div>
<div id="packages-needed" class="section level1">
<h1><span class="header-section-number">4</span> Packages needed</h1>
<pre class="r"><code>library(here) # to set file path if working from local file
library(tidyverse) # readr, ggplot2, dplyr</code></pre>
</div>
<div id="read-in-the-data" class="section level1">
<h1><span class="header-section-number">5</span> Read in the data</h1>
<p>Note! This is not the original data- I did a lot of cleaning and decision-making in the pre-processing. The below contains only paintings and drawings in the MoMA collection.</p>
<p>Use this code chunk to read in the data available at <a href="http://bit.ly/cs631-moma" class="uri">http://bit.ly/cs631-moma</a>:</p>
<pre class="r"><code>library(readr)
moma <- read_csv("http://bit.ly/cs631-moma")</code></pre>
<p>I called my cleaned data <code>artworks-cleaned.csv</code>, and stored it in a folder called <code>data</code>. You can use this code if you want to read in the local CSV file.</p>
<pre class="r"><code>library(here)
library(readr)
library(dplyr)
moma <- read_csv(here::here("data", "artworks-cleaned.csv"))</code></pre>
</div>
<div id="know-your-data" class="section level1">
<h1><span class="header-section-number">6</span> Know your data</h1>
<div class="panel panel-success">
<div class="panel-heading">
Challenge #1:
</div>
<div class="panel-body">
<p>Try to answer all of these questions using <code>dplyr</code>. Answers are below but try them on your own first!</p>
<ol style="list-style-type: decimal">
<li>How many paintings (rows) are in <code>moma</code>? How many variables (columns) are in <code>moma</code>?</li>
<li>What is the first painting acquired by MoMA? Which year? Which artist? What title?</li>
<li>What is the oldest painting in the collection? Which year? Which artist? What title?</li>
<li>How many distinct artists are there?</li>
<li>Which artist has the most paintings in the collection? How many paintings are by this artist?</li>
<li>How many paintings by male vs female artists?</li>
</ol>
<p>If you want more:</p>
<ol style="list-style-type: decimal">
<li>How many artists of each gender are there?</li>
<li>In what year were the most paintings acquired? Created?</li>
<li>In what year was the first painting by a (solo) female artist acquired? When was that painting created? Which artist? What title?
</div></li>
</ol>
</div>
<div id="how-many-paintings" class="section level2">
<h2><span class="header-section-number">6.1</span> How many paintings?</h2>
<ul>
<li>How many rows/observations are in <code>moma</code>?</li>
<li>How many variables are in <code>moma</code>?</li>
</ul>
<p class="text-info">
<strong>Hint:</strong> These questions can be answered using the <code>dplyr</code> function <code>glimpse</code>.
</p>
<pre class="r"><code>library(dplyr)
moma</code></pre>
<pre><code># A tibble: 2,253 x 23
title artist artist_bio artist_birth_ye… artist_death_ye… num_artists
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 Rope … Joan M… (Spanish,… 1893. 1983. 1.
2 Fire … Paul K… (German, … 1879. 1940. 1.
3 Portr… Paul K… (German, … 1879. 1940. 1.
4 Guitar Pablo … (Spanish,… 1881. 1973. 1.
5 Grand… Arthur… (American… 1880. 1946. 1.
6 "\"M'… Franci… (French, … 1879. 1953. 1.
7 Untit… Blinky… (German, … 1943. 1977. 1.
8 Dayli… Pierre… (French, … 1880. 1950. 1.
9 The B… Paul C… (French, … 1839. 1906. 1.
10 Synth… Enrico… (Italian,… 1894. 1956. 1.
# ... with 2,243 more rows, and 17 more variables: n_female_artists <dbl>,
# n_male_artists <dbl>, artist_gender <chr>, year_acquired <dbl>,
# year_created <dbl>, circumference_cm <lgl>, depth_cm <dbl>,
# diameter_cm <lgl>, height_cm <dbl>, length_cm <lgl>, width_cm <dbl>,
# seat_height_cm <lgl>, purchase <lgl>, gift <lgl>, exchange <lgl>,
# classification <chr>, department <chr></code></pre>
<pre class="r"><code>glimpse(moma)</code></pre>
<pre><code>Observations: 2,253
Variables: 23
$ title <chr> "Rope and People, I", "Fire in the Evening",...
$ artist <chr> "Joan Miró", "Paul Klee", "Paul Klee", "Pabl...
$ artist_bio <chr> "(Spanish, 1893–1983)", "(German, born Switz...
$ artist_birth_year <dbl> 1893, 1879, 1879, 1881, 1880, 1879, 1943, 18...
$ artist_death_year <dbl> 1983, 1940, 1940, 1973, 1946, 1953, 1977, 19...
$ num_artists <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
$ n_female_artists <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
$ n_male_artists <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
$ artist_gender <chr> "Male", "Male", "Male", "Male", "Male", "Mal...
$ year_acquired <dbl> 1936, 1970, 1966, 1955, 1939, 1968, 1997, 19...
$ year_created <dbl> 1935, 1929, 1927, 1919, 1925, 1919, 1970, 19...
$ circumference_cm <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ depth_cm <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ diameter_cm <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ height_cm <dbl> 104.8, 33.8, 60.3, 215.9, 50.8, 129.2, 200.0...
$ length_cm <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ width_cm <dbl> 74.6, 33.3, 36.8, 78.7, 54.0, 89.9, 200.0, 3...
$ seat_height_cm <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
$ purchase <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA...
$ gift <lgl> TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE,...
$ exchange <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FAL...
$ classification <chr> "Painting", "Painting", "Painting", "Paintin...
$ department <chr> "Painting & Sculpture", "Painting & Sculptur...</code></pre>
<p>There are 2253 paintings in <code>moma</code>.</p>
</div>
<div id="what-is-the-first-painting-acquired" class="section level2">
<h2><span class="header-section-number">6.2</span> What is the first painting acquired?</h2>
<ul>
<li>What is the first painting acquired by MoMA (since they started tracking)?</li>
<li>What year was it acquired?</li>
<li>Which artist?</li>
<li>What title?</li>
</ul>
<p class="text-info">
<strong>Hint:</strong> These questions can be answered by combining two <code>dplyr</code> functions: <code>select</code> and <code>arrange</code>.
</p>
<pre class="r"><code>moma %>%
select(artist, title, year_acquired) %>%
arrange(year_acquired)</code></pre>
<pre><code># A tibble: 2,253 x 3
artist title year_acquired
<chr> <chr> <dbl>
1 Edward Hopper House by the Railroad 1930.
2 Bernard Karfiol Seated Nude 1930.
3 Pierre Roy Daylight Savings Time 1931.
4 Preston Dickinson Plums on a Plate 1931.
5 Otto Dix Dr. Mayer-Hermann 1932.
6 Paul Cézanne The Bather 1934.
7 Paul Cézanne Pines and Rocks (Fontainebleau?) 1934.
8 Paul Cézanne Still Life with Ginger Jar, Sugar Bowl… 1934.
9 Paul Cézanne Still Life with Apples 1934.
10 Arthur B. Davies Italian Landscape 1934.
# ... with 2,243 more rows</code></pre>
</div>
<div id="what-is-the-oldest-painting-in-the-moma-collection" class="section level2">
<h2><span class="header-section-number">6.3</span> What is the oldest painting in the MoMA collection?</h2>
<ul>
<li>What is the oldest painting in the MoMA collection historically (since they started tracking)?</li>
<li>What year was it created?</li>
<li>Which artist?</li>
<li>What title?</li>
</ul>
<p class="text-info">
<strong>Hint:</strong> These questions can be answered by combining two <code>dplyr</code> functions: <code>select</code> and <code>arrange</code>.
</p>
<pre class="r"><code>moma %>%
select(artist, title, year_created) %>%
arrange(year_created)</code></pre>
<pre><code># A tibble: 2,253 x 3
artist title year_created
<chr> <chr> <dbl>
1 Odilon Redon Landscape at Daybreak 1872.
2 Odilon Redon Apache (Man on Horseback) 1875.
3 Odilon Redon Apache (Man on Horseback II) 1875.
4 Odilon Redon Fishing Boat 1875.
5 Odilon Redon Rocky Peak 1875.
6 Odilon Redon The Rocky Slope 1875.
7 Odilon Redon Landscape with Rocks, near Royan 1875.
8 Paul Cézanne Still Life with Fruit Dish 1879.
9 Paul Cézanne L'Estaque 1879.
10 Claude Monet On the Cliff at Pourville, Clear Weather 1882.
# ... with 2,243 more rows</code></pre>
<p>To do inline comments, I could say that the oldest painting is Landscape at Daybreak, painted by Odilon Redon in 1872.</p>
</div>
<div id="how-many-artists" class="section level2">
<h2><span class="header-section-number">6.4</span> How many artists?</h2>
<ul>
<li>How many distinct artists are there?</li>
</ul>
<p class="text-info">
<strong>Hint:</strong> Try <code>dplyr::distinct</code>.
</p>
<pre class="r"><code>moma %>%
distinct(artist)</code></pre>
<pre><code># A tibble: 989 x 1
artist
<chr>
1 Joan Miró
2 Paul Klee
3 Pablo Picasso
4 Arthur Dove
5 Francis Picabia
6 Blinky Palermo
7 Pierre Roy
8 Paul Cézanne
9 Enrico Prampolini
10 Jankel Adler
# ... with 979 more rows</code></pre>
<p>You could add a <code>tally()</code> too to get just the number of rows. You can also then use <code>pull()</code> to get that single number out of the tibble:</p>
<pre class="r"><code>num_artists <- moma %>%
distinct(artist) %>%
tally() %>%
pull()
num_artists</code></pre>
<pre><code>[1] 989</code></pre>
<p>Then I can refer to this number in inline comments like: there are 989 total.</p>
</div>
<div id="which-artist-has-the-most-paintings" class="section level2">
<h2><span class="header-section-number">6.5</span> Which artist has the most paintings?</h2>
<ul>
<li>Which artist has the most paintings ever owned by <code>moma</code>?</li>
<li>How many paintings in the MoMA collection by that artist?</li>
</ul>
<p class="text-info">
<strong>Hint:</strong> Try <code>dplyr::count</code>. Use <code>?count</code> to figure out how to sort the output.
</p>
<pre class="r"><code>moma %>%
count(artist, sort = TRUE)</code></pre>
<pre><code># A tibble: 989 x 2
artist n
<chr> <int>
1 Pablo Picasso 55
2 Henri Matisse 32
3 On Kawara 32
4 Jacob Lawrence 30
5 Batiste Madalena 25
6 Jean Dubuffet 25
7 Odilon Redon 25
8 Ben Vautier 24
9 Frank Stella 23
10 Philip Guston 23
# ... with 979 more rows</code></pre>
<p>In the <code>?count</code> documentation, it says: “<code>count</code> and <code>tally</code> are designed so that you can call them repeatedly, each time rolling up a level of detail.” Try running <code>count()</code> again (leave parentheses empty) on your last code chunk.</p>
<pre class="r"><code>moma %>%
count(artist, sort = TRUE) %>%
count()</code></pre>
<pre><code># A tibble: 1 x 1
nn
<int>
1 989</code></pre>
</div>
<div id="how-many-paintings-by-male-vs-female-artists" class="section level2">
<h2><span class="header-section-number">6.6</span> How many paintings by male vs female artists?</h2>
<pre class="r"><code>moma %>%
count(artist_gender)</code></pre>
<pre><code># A tibble: 3 x 2
artist_gender n
<chr> <int>
1 Female 252
2 Male 1991
3 <NA> 10</code></pre>
<p>Now together we’ll count the number of artists by gender. You’ll need to give <code>count</code> two variable names in the parentheses: <code>artist_gender</code> and <code>artist</code>.</p>
<pre class="r"><code>moma %>%
count(artist_gender, artist, sort = TRUE) </code></pre>
<pre><code># A tibble: 989 x 3
artist_gender artist n
<chr> <chr> <int>
1 Male Pablo Picasso 55
2 Male Henri Matisse 32
3 Male On Kawara 32
4 Male Jacob Lawrence 30
5 Male Batiste Madalena 25
6 Male Jean Dubuffet 25
7 Male Odilon Redon 25
8 Male Ben Vautier 24
9 Male Frank Stella 23
10 Male Philip Guston 23
# ... with 979 more rows</code></pre>
<p>This output is not superhelpful as we already know that Pablo Picasso has 55 paintings in the MoMA collection. But how can we find out which female artist has the most paintings? We have a few options. Let’s first add a <code>filter</code> for females.</p>
<pre class="r"><code>moma %>%
count(artist_gender, artist, sort = TRUE) %>%
filter(artist_gender == "Female")</code></pre>
<pre><code># A tibble: 143 x 3
artist_gender artist n
<chr> <chr> <int>
1 Female Sherrie Levine 12
2 Female Agnes Martin 9
3 Female Elizabeth Murray 8
4 Female Susan Rothenberg 8
5 Female Joan Mitchell 6
6 Female Loren MacIver 6
7 Female R. H. Quaytman 6
8 Female Helen Frankenthaler 5
9 Female Georgia O'Keeffe 4
10 Female Lynette Yiadom-Boakye 4
# ... with 133 more rows</code></pre>
<p>Another option is to use another <code>dplyr</code> function called <code>top_n()</code>. Use <code>?top_n</code> to see how it works. How it won’t work in this context:</p>
<pre class="r"><code>moma %>%
count(artist_gender, artist, sort = TRUE) %>%
top_n(2)</code></pre>
<pre><code># A tibble: 3 x 3
artist_gender artist n
<chr> <chr> <int>
1 Male Pablo Picasso 55
2 Male Henri Matisse 32
3 Male On Kawara 32</code></pre>
<p>How it will work better is following a <code>group_by(artist_gender)</code>:</p>
<pre class="r"><code>moma %>%
count(artist_gender, artist, sort = TRUE) %>%
group_by(artist_gender) %>%
top_n(1)</code></pre>
<pre><code># A tibble: 3 x 3
# Groups: artist_gender [3]
artist_gender artist n
<chr> <chr> <int>
1 Male Pablo Picasso 55
2 Female Sherrie Levine 12
3 <NA> Gilbert & George, Gilbert Proesch, George Passmore 2</code></pre>
<p>Now we can see that Sherrie Levine has 12 paintings. This is a pretty far cry from the 55 paintings by Pablo Picasso.</p>
</div>
<div id="how-many-artists-of-each-gender-are-there" class="section level2">
<h2><span class="header-section-number">6.7</span> How many artists of each gender are there?</h2>
<p>This is a harder question to answer than you think! This is because the level of observation in our current <code>moma</code> dataset is <em>unique paintings</em>. We have multiple paintings done by the same artists though, so counting just the number of unique paintings is different than counting the number of unique artists.</p>
<p>Remember how <code>count</code> can be used back-to-back to roll up a level of detail? Try running <code>count(artist_gender)</code> again on your last code chunk.</p>
<pre class="r"><code>moma %>%
count(artist_gender, artist) %>%
count(artist_gender)</code></pre>
<pre><code># A tibble: 3 x 2
artist_gender nn
<chr> <int>
1 Female 143
2 Male 837
3 <NA> 9</code></pre>
<p>This output takes the previous table (made with <code>count(artist_gender, artist)</code>), and essentially ignores the <code>n</code> column. So we no longer care about how <em>many</em> paintings each individual artist created. Instead, we want to <code>count</code> the rows in this <em>new</em> table where each row is a unique artist. By counting by <code>artist_gender</code> in the last line, we are grouping by levels of that variable (so Female/Male/<code>NA</code>) and <code>nn</code> is the number of unique artists for each gender category recorded.</p>
</div>
<div id="when-were-the-most-paintings-in-the-collection-acquired" class="section level2">
<h2><span class="header-section-number">6.8</span> When were the most paintings in the collection acquired?</h2>
<p class="text-info">
<strong>Hint:</strong> Try <code>dplyr::count</code>. Use <code>?count</code> to figure out how to sort the output.
</p>
<pre class="r"><code>moma %>%
count(year_acquired, sort = TRUE)</code></pre>
<pre><code># A tibble: 88 x 2
year_acquired n
<dbl> <int>
1 1985. 86
2 1942. 71
3 1979. 71
4 1991. 67
5 2005. 67
6 1967. 65
7 2008. 55
8 1961. 45
9 1969. 45
10 1956. 42
# ... with 78 more rows</code></pre>
</div>
<div id="when-were-the-most-paintings-in-the-collection-created" class="section level2">
<h2><span class="header-section-number">6.9</span> When were the most paintings in the collection created?</h2>
<p class="text-info">
<strong>Hint:</strong> Try <code>dplyr::count</code>. Use <code>?count</code> to figure out how to sort the output.
</p>
<pre class="r"><code>moma %>%
count(year_created, sort = TRUE)</code></pre>
<pre><code># A tibble: 139 x 2
year_created n
<dbl> <int>
1 1977. 57
2 1940. 56
3 1964. 56
4 1961. 50
5 1962. 49
6 1963. 44
7 1959. 42
8 1968. 40
9 1960. 39
10 1914. 37
# ... with 129 more rows</code></pre>
</div>
<div id="what-about-the-first-painting-by-a-solo-female-artist" class="section level2">
<h2><span class="header-section-number">6.10</span> What about the first painting by a solo female artist?</h2>
<p class="text-info">
<strong>Hint:</strong> Try combining three <code>dplyr</code> functions: <code>filter</code>, <code>select</code>, and <code>arrange</code>.
</p>
<p>When was the first painting by a solo female artist acquired?</p>
<pre class="r"><code>moma %>%
filter(num_artists == 1 & n_female_artists == 1) %>%
select(title, artist, year_acquired, year_created) %>%
arrange(year_acquired)</code></pre>
<pre><code># A tibble: 252 x 4
title artist year_acquired year_created
<chr> <chr> <dbl> <dbl>
1 Landscape, 47 Natalia Gon… 1937. 1912.
2 Shack Loren MacIv… 1938. 1934.
3 Hopscotch Loren MacIv… 1940. 1940.
4 Shadows with Painting Irene Rice … 1941. 1940.
5 Figure Varvara Ste… 1941. 1921.
6 Still Life in Red Amelia Pelá… 1942. 1938.
7 White Lines Irene Rice … 1942. 1942.
8 Musical Squash Maud Morgan 1942. 1942.
9 Desolation Raquel Forn… 1942. 1942.
10 Self-Portrait with Cropped Hair Frida Kahlo 1943. 1940.
# ... with 242 more rows</code></pre>
<p>What is the oldest painting by a solo female artist, and when was it created?</p>
<pre class="r"><code>moma %>%
filter(num_artists == 1 & n_female_artists == 1) %>%
select(title, artist, year_acquired, year_created) %>%
arrange(year_created)</code></pre>
<pre><code># A tibble: 252 x 4
title artist year_acquired year_created
<chr> <chr> <dbl> <dbl>
1 Self-Portrait with Two Flower… Paula Moders… 2017. 1907.
2 Girl with Bare Shoulders Gwen John 1958. 1909.
3 Girl Reading at a Window Gwen John 1971. 1911.
4 Landscape, 47 Natalia Gonc… 1937. 1912.
5 Cubist Nude Alexandra Ex… 1991. 1912.
6 Rayonism, Blue-Green Forest Natalia Gonc… 1985. 1913.
7 The Factory and the Bridge Olga Rozanova 1985. 1913.
8 Subject from a Dyer's Shop Lyubov Popova 1985. 1914.
9 Portuguese Market Sonia Delaun… 1955. 1915.
10 Girl with a Blue Scarf Gwen John 1963. 1915.
# ... with 242 more rows</code></pre>
<pre class="r"><code># or, because artist_gender is missing when num_artists > 1
moma %>%
filter(artist_gender == "Female") %>%
select(title, artist, year_acquired, year_created) %>%
arrange(year_acquired)</code></pre>
</div>
</div>
<div id="basics-of-ggplot2" class="section level1">
<h1><span class="header-section-number">7</span> Basics of <code>ggplot2</code></h1>
<div class="panel panel-success">
<div class="panel-heading">
Challenge #2:
</div>
<div class="panel-body">
We’ll do this together <em>(nothing to turn in)</em>: see <a href="https://apreshill.github.io/data-vis-labs-2018/slides/02-slides.html#16">slides</a>.
</div>
</div>
</div>
<div id="plot-your-data" class="section level1">
<h1><span class="header-section-number">8</span> Plot your data</h1>
<div id="plot-year-painted-vs-year-acquired" class="section level2">
<h2><span class="header-section-number">8.1</span> Plot year painted vs year acquired</h2>
<div class="panel panel-success">
<div class="panel-heading">
Challenge #3:
</div>
<div class="panel-body">
<p>Let’s recreate this plot from <a href="https://fivethirtyeight.com/features/a-nerds-guide-to-the-2229-paintings-at-moma/">fivethirtyeight</a> (mostly)!</p>
<div class="figure">
<img src="https://espnfivethirtyeight.files.wordpress.com/2015/08/roeder-feature-moma-1.png?w=1150&quality=90&strip=info" />
</div>
<p>Things to consider:</p>
<ul>
<li>You’ll want to play around with setting an <code>alpha</code> value here- keep in mind that <code>0</code> is totally transparent and <code>1</code> is opaque.</li>
<li>Try using <code>geom_abline()</code> to add the line in red (use the default intercept value of 0). The actual red line is difficult to recreate- here is what the authors say: “The red regression line shows the “modernizing” of MoMA’s collection — how quickly the museum has moved toward acquiring recent paintings.”</li>
<li>Go back to <a href="https://apreshill.github.io/data-vis-labs-2018/01-eda_hot_dogs.html">Lab 01</a> to review how to do the following:
<ul>
<li>Change the x- and y-axis labels and the plot title to match the plot above
</div></li>
</ul></li>
</ul>
</div>
<pre class="r"><code>ggplot(moma, aes(year_created, year_acquired)) +
geom_point(alpha = .1, na.rm = TRUE) +
geom_abline(intercept = c(0,0), colour = "red") +
labs(x = "Year Painted", y = "Year Acquired") +
ggtitle("MoMA Keeps Its Collection Current") </code></pre>
<p><img src="02-moma_files/figure-html/unnamed-chunk-26-1.png" width="672" /></p>
</div>
<div id="facet-by-artist-gender" class="section level2">
<h2><span class="header-section-number">8.2</span> Facet by artist gender</h2>
<p>Can you make the same plot above, but facet by artist gender?</p>
<p class="text-info">
<strong>Hint:</strong> For this to make sense, you probably want to do some filtering to select only those paintings where there was one “solo” artist.
</p>
<pre class="r"><code>moma_solo <- moma %>%
filter(num_artists == 1)
ggplot(moma_solo, aes(year_created, year_acquired)) +
geom_point(alpha = .1) +
geom_abline(intercept = c(0,0), colour = "red") +
labs(x = "Year Painted", y = "Year Acquired") +
ggtitle("MoMA Keeps Its Collection Current") +
facet_wrap(~artist_gender)</code></pre>
<p><img src="02-moma_files/figure-html/unnamed-chunk-27-1.png" width="672" /></p>
</div>
</div>
<div id="plot-painting-dimensions" class="section level1">
<h1><span class="header-section-number">9</span> Plot painting dimensions</h1>
<div class="panel panel-success">
<div class="panel-heading">
Challenge #4:
</div>
<div class="panel-body">
<p>Let’s (somewhat) try to recreate this scatterplot from <a href="https://fivethirtyeight.com/features/a-nerds-guide-to-the-2229-paintings-at-moma/">fivethirtyeight</a>.</p>
<div class="figure">
<img src="https://espnfivethirtyeight.files.wordpress.com/2015/08/roeder-feature-moma-3.png?w=1150&quality=90&strip=info" />
</div>
<p>To recreate, some things to consider:</p>
<ul>
<li>Try filtering all paintings with height less than 600 cm and width less than 760 cm.</li>
<li>If you want to add color as in the original, you’ll need to create a new variable using <code>mutate</code>.</li>
</ul>
<p class="text-info">
<strong>Hint:</strong> You’ll probably also want to look into <code>case_when</code> to create a categorical variable to color by.
</p>
</div>
</div>
<pre class="r"><code>moma_dim <- moma %>%
filter(height_cm < 600, width_cm < 760) %>%
mutate(hw_ratio = height_cm / width_cm,
hw_cat = case_when(
hw_ratio > 1 ~ "taller than wide",
hw_ratio < 1 ~ "wider than tall",
hw_ratio == 1 ~ "perfect square"
))
library(ggthemes)
ggplot(moma_dim, aes(x = width_cm, y = height_cm, colour = hw_cat)) +
geom_point(alpha = .5) +
ggtitle("MoMA Paintings, Tall and Wide") +
scale_colour_manual(name = "",
values = c("gray50", "#FF9900", "#B14CF0")) +
theme_fivethirtyeight() +
theme(axis.title = element_text()) +
labs(x = "Width", y = "Height") </code></pre>
<p><img src="02-moma_files/figure-html/unnamed-chunk-28-1.png" width="672" /></p>
<p>Because Grace is right, we can do better with colors!</p>
<pre class="r"><code>library(ggthemes)
ggplot(moma_dim, aes(x = width_cm, y = height_cm, colour = hw_cat)) +
geom_point(alpha = .5) +
ggtitle("MoMA Paintings, Tall and Wide") +
scale_colour_manual(name = "",
values = c("gray50", "#ee5863", "#6999cd")) +
theme_fivethirtyeight() +
theme(axis.title = element_text()) +
labs(x = "Width", y = "Height") </code></pre>
<p><img src="02-moma_files/figure-html/unnamed-chunk-29-1.png" width="672" /></p>
<p>We could also do away with the legend and use <code>geom_annotate</code> instead.</p>
<pre class="r"><code>library(ggthemes)
ggplot(moma_dim, aes(x = width_cm, y = height_cm, colour = hw_cat)) +
geom_point(alpha = .5, show.legend = FALSE) +
ggtitle("MoMA Paintings, Tall and Wide") +
scale_colour_manual(name = "",
values = c("gray50", "#ee5863", "#6999cd")) +
theme_fivethirtyeight() +
theme(axis.title = element_text()) +
labs(x = "Width", y = "Height") +
annotate(x = 200, y = 380, geom = "text",
label = "Taller than\nWide", color = "#ee5863",
size = 5, family = "Lato", hjust = 1, fontface = 2) +
annotate(x = 375, y = 100, geom = "text",
label = "Wider than\nTall", color = "#6999cd",
size = 5, family = "Lato", hjust = 0, fontface = 2)</code></pre>
<p><img src="02-moma_files/figure-html/unnamed-chunk-30-1.png" width="672" /></p>
</div>
<div id="plot-something-new-different" class="section level1">
<h1><span class="header-section-number">10</span> Plot something new & different!</h1>
<div class="panel panel-success">
<div class="panel-heading">
Challenge #5:
</div>
<div class="panel-body">
<p>It can be anything- you can change colors, add annotations, switch the geoms, add new variables to examine- the world is your oyster! The only requirements are:</p>
<ol style="list-style-type: decimal">
<li>You <em>make</em> one new plot that is original, and</li>
<li>You <em>write</em> 1-2 sentences to present the plot and why it makes sense. What questions do you think your plot can help you to answer?</li>
</ol>
It does not have to be pretty right now, but it must make sense as a visualization- you must be able to intelligently and succintly tell us about it in real words.
</div>
</div>
</div>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">
<img alt="Creative Commons License" style="border-width:0" src="by-nc.png" height="400" width="65"/></a>
</p>
</div>
</div>
</div>
<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>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>