<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/visualizing-the-spanish-contribution-to-the-metropolitan-museum-of-art/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://fronkonstin.com/2017/09/21/visualizing-the-spanish-contribution-to-the-metropolitan-museum-of-art/"> R – Fronkonstin</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div class="twitter-share"><a rel="nofollow" href="https://twitter.com/intent/tweet?url=https%3A%2F%2Ffronkonstin.com%2F2017%2F09%2F21%2Fvisualizing-the-spanish-contribution-to-the-metropolitan-museum-of-art%2F&via=aschinchon" class="twitter-share-button" target="_blank">Tweet</a></div>
<blockquote><p>Well I walk upon the river like it’s easier than land<br>
(Love is All, The Tallest Man on Earth)</p>
</blockquote>
<p><img data-orig-file="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/09/co.ep_.1971.86_16.1.jpg?fit=880%2C1024&amp;ssl=1" data-orig-size="880,1024" data-medium-file="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/09/co.ep_.1971.86_16.1.jpg?fit=258%2C300&amp;ssl=1" data-attachment-id="4241" data-image-meta="{" data-image-description="" src="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/09/co.ep_.1971.86_16.1.jpg?resize=258%2C300&ssl=1" data-permalink="https://fronkonstin.com/2017/09/21/visualizing-the-spanish-contribution-to-the-metropolitan-museum-of-art/co-ep-1971-86_16-1/" data-large-file="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/09/co.ep_.1971.86_16.1.jpg?fit=604%2C703&amp;ssl=1" alt="" data-image-title="co.ep.1971.86_16.1" sizes="(max-width: 258px) 100vw, 258px" data-comments-opened="1" class="wp-image-4241" data-recalc-dims="1"><br>
The Metropolitan Museum of Art provides <a rel="nofollow" href="https://github.com/metmuseum/openaccess" target="_blank">here</a> a dataset with information on more than 450.000 artworks in its collection. You can do anything you want with these data: there are no restrictions of use. Each record contains information about the author, title, type of work, dimensions, date, culture and  geography of a particular piece.</p>
<p>I can imagine a bunch of things to do with these data but since I am a big fan of <a rel="nofollow" href="http://jkunst.com/highcharter/" target="_blank">highcharter</a>,  I have done a treemap, which is an <em>artistic</em> (as well as efficient) way to visualize hierarchical data. A treemap is useful to visualize frequencies. They can handle levels, allowing to navigate to go into detail about any category. <a rel="nofollow" href="https://www.highcharts.com/demo/treemap-large-dataset" target="_blank">Here</a> you can find a good example of treemap.</p>
<p>To read data I use <code>fread</code> function from <code>data.table</code> package. I also use this package to do some <em>data wrangling</em> operations on the data set. After them, I filter it looking for the word <code>SPANISH</code> in the columns <code>Artist Nationality</code> and <code>Culture</code> and looking for the word <code>SPAIN</code> in the column <code>Country</code>. For me, any piece created by an Spanish artist (like <a rel="nofollow" href="http://www.metmuseum.org/art/collection/search/360151" target="_blank">this one</a>), coming from Spanish culture (like <a rel="nofollow" href="http://www.metmuseum.org/art/collection/search/460993" target="_blank">this one</a>) or from Spain (like <a rel="nofollow" href="http://www.metmuseum.org/art/collection/search/444449" target="_blank">this one</a>) is Spanish (this is my very own definition and may do not match with any academical one). Once it is done, it is easy to extract some interesting figures:</p>
<ul>
<li>There are 5.294 Spanish pieces in The Met, which means a 1,16% of the collection</li>
<li>This percentage varies significantly between departments: it raises to 9,01% in <em>The Cloisters</em> and to 4,83% in <em>The Robert Lehman Collection</em>; on the other hand, it falls to 0.52% in <em>The Libraries</em> and to 0,24% in <em>Photographs</em>.</li>
<li>The Met is home to 1.895 highlights and 44 of them (2,32%) are Spanish; It means that Spanish art is twice as important as could be expected (remember that represents a 1,16% of the entire collection)</li>
</ul>
<p>My treemap represents the distribution of Spanish artworks by department (column <code>Department</code>) and type of work (column <code>Classification</code>). There are two important things to know before doing a treemap with <code>highcharter</code>:</p>
<ul>
<li>You have to use <code>treemap</code> function from <code>treemap</code> package to create a list with your data frame that will serve as input for <code>hctreemap</code> function</li>
<li><code>hctreemap </code>fails if some category name is the same as any of its subcategories. To avoid this, make sure that all names are distinct.</li>
</ul>
<p>This is the treemap:</p>
<p><br>
<iframe src="https://fronkonstin.com/wp-content/uploads/2017/09/metplot.html" width="100%" height="500"></iframe>
</p>
<p><a rel="nofollow" href="https://fronkonstin.com/wp-content/uploads/2017/09/metplot.html" target="_blank">Here</a> you can see a full size version of it.</p>
<p>There can be seen several things at a glance: most of the pieces are <em>drawings and prints</em> and <em>european sculpture and decorative arts</em> (in concrete, <em>prints</em> and <em>textiles</em>), there is also big number of <em>costumes, arms and armor</em> is a very fragmented department … I think treemap is a good way to see what kind of works owns The Met.</p>
<p>Mi favorite spanish piece in The Met is the stunning <a rel="nofollow" href="http://www.metmuseum.org/art/collection/search/437869" target="_blank">Portrait of Juan de Pareja</a> by Velázquez, which illustrates this post: how nice would be to see it next to <a rel="nofollow" href="https://www.museodelprado.es/en/the-collection/art-work/the-buffoon-el-primo/cc7a8493-e2ff-4d33-a0d0-91d7dc210d5a" target="_blank">El Primo</a> in El Museo del Prado!</p>
<p>Feel free to use my code to do your own experiments:</p>
<pre>
library(data.table)
library(dplyr)
library(stringr)
library(highcharter)
library(treemap)

file=&quot;MetObjects.csv&quot;
# Download data
if (!file.exists(file)) download.file(paste0(&quot;https://media.githubusercontent.com/media/metmuseum/openaccess/master/&quot;, file), 
                                      destfile=file,
                                      mode='wb')
# Read data
data=fread(file, sep=&quot;,&quot;, encoding=&quot;UTF-8&quot;)

# Modify column names to remove blanks
colnames(data)=gsub(&quot; &quot;, &quot;.&quot;, colnames(data))

# Clean columns to prepare for searching
data[,`:=`(Artist.Nationality_aux=toupper(Artist.Nationality) %>% str_replace_all(&quot;\\[\\d+\\]&quot;, &quot;&quot;) %>% 
             iconv(from='UTF-8', to='ASCII//TRANSLIT'),
           Culture_aux=toupper(Culture) %>% str_replace_all(&quot;\\[\\d+\\]&quot;, &quot;&quot;) %>% 
             iconv(from='UTF-8', to='ASCII//TRANSLIT'),
           Country_aux=toupper(Country) %>% str_replace_all(&quot;\\[\\d+\\]&quot;, &quot;&quot;) %>% 
             iconv(from='UTF-8', to='ASCII//TRANSLIT'))]

# Look for Spanish artworks
data[Artist.Nationality_aux %like% &quot;SPANISH&quot; | 
       Culture_aux %like% &quot;SPANISH&quot; | 
       Country_aux %like% &quot;SPAIN&quot;] -> data_spain

# Count artworks by Department and Classification
data_spain %>% 
  mutate(Classification=ifelse(Classification=='', &quot;miscellaneous&quot;, Classification)) %>% 
  mutate(Department=tolower(Department),
         Classification1=str_match(Classification, &quot;(\\w+)(-|,|\\|)&quot;)[,2],
         Classification=ifelse(!is.na(Classification1), 
                               tolower(Classification1), 
                               tolower(Classification))) %>% 
  group_by(Department, Classification) %>% 
  summarize(Objects=n()) %>% 
  ungroup %>% 
  mutate(Classification=ifelse(Department==Classification, paste0(Classification, &quot;#&quot;), 
                               Classification)) %>% 
  as.data.frame() -> dfspain

# Do treemap without drawing
tm_dfspain &lt;- treemap(dfspain, index = c(&quot;Department&quot;, &quot;Classification&quot;),
                      draw=F,
                      vSize = &quot;Objects&quot;, 
                      vColor = &quot;Objects&quot;,
                      type = &quot;index&quot;)

# Do highcharter treemap 
hctreemap(
  tm_dfspain,
  allowDrillToNode = TRUE,
  allowPointSelect = T,
  levelIsConstant = F,
  levels = list(
    list(
      level = 1,
      dataLabels = list (enabled = T, color = '#f7f5ed', style = list(&quot;fontSize&quot; = &quot;1em&quot;)),
      borderWidth = 1
    ),
    list(
      level = 2,
      dataLabels = list (enabled = F,  align = 'right', verticalAlign = 'top', 
                         style = list(&quot;textShadow&quot; = F, &quot;fontWeight&quot; = 'light', &quot;fontSize&quot; = &quot;1em&quot;)),
      borderWidth = 0.7
    ) 
  )) %>% 
  hc_title(text = &quot;Spanish Artworks in The Met&quot;) %>% 
  hc_subtitle(text = &quot;Distribution by Department&quot;) -> plot

plot
</pre>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://fronkonstin.com/2017/09/21/visualizing-the-spanish-contribution-to-the-metropolitan-museum-of-art/"> R – Fronkonstin</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/VcdNohfRLOc" height="1"></a></div>