<?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>300em30</title>
<link>https://biamuniz.github.io/300em30/blog/</link>
<atom:link href="https://biamuniz.github.io/300em30/blog/index.xml" rel="self" type="application/rss+xml"/>
<description>Textos sobre shows, memórias e música ao vivo.</description>
<generator>quarto-1.6.37</generator>
<lastBuildDate>Tue, 03 Nov 2026 03:00:00 GMT</lastBuildDate>
<item>
  <title>Como fiz o treemap de todos os shows que vi desde 2013</title>
  <link>https://biamuniz.github.io/300em30/blog/posts/treemap-shows/</link>
  <description><![CDATA[ 




<section id="a-ideia" class="level2">
<h2 data-anchor-id="a-ideia">A ideia</h2>
<p>Desde 2013 eu anoto numa planilha todo show que vejo: o artista, a data, o lugar, se é nacional ou internacional e se foi um dos meus favoritos. Em 2024 resolvi transformar essa lista num gráfico. O resultado foi um treemap em que cada retângulo é um artista e a área mostra quantas vezes eu vi aquele artista ao vivo.</p>
<p>Neste post eu mostro o passo a passo em R, do CSV até o PNG final, com textura de papel amassado e fonte de ingresso. Também mostro as versões que deram errado, porque foram umas seis até chegar num resultado de que eu gostei.</p>
<p>O gráfico tem três camadas de informação:</p>
<ul>
<li><strong>Área do retângulo:</strong> quantidade de shows daquele artista.</li>
<li><strong>Cor:</strong> bege para artistas nacionais, azul para internacionais.</li>
<li><strong>Anos no canto inferior direito:</strong> um ano por show; os que têm asterisco (*2019) foram meus favoritos.</li>
</ul>
</section>
<section id="o-que-você-vai-precisar" class="level2">
<h2 data-anchor-id="o-que-você-vai-precisar">O que você vai precisar</h2>
<p><strong>Os dados.</strong> Uma linha por show. Minha planilha tem muitas colunas (local, endereço, com quem fui, setlist), mas para este gráfico só uso quatro: <code>SHOW</code>, <code>ANO</code>, <code>INTERNACIONAL</code> (“NACIONAL” ou “INTERNACIONAL”) e <code>FAV</code> (“SIM” ou “NÃO”).</p>
<p><strong>Os pacotes:</strong></p>
<div class="cell">
<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;">install.packages</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;">"tidyverse"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"janitor"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"treemapify"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"png"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ragg"</span>))</span></code></pre></div>
</div>
<ul>
<li><code>janitor</code> limpa os nomes das colunas.</li>
<li><code>treemapify</code> adiciona o <code>geom_treemap()</code> ao ggplot2.</li>
<li><code>png</code> (junto com o <code>grid</code>, que já vem com o R) carrega a imagem de fundo.</li>
<li><code>ragg</code> desenha e salva o gráfico usando as fontes instaladas no computador.</li>
</ul>
<p><strong>Uma fonte com cara de ingresso.</strong> Usei a OCR A Std, a fonte daqueles números impressos em boletos e tickets. Instale no sistema antes de começar.</p>
<p><strong>Uma textura de fundo.</strong> Usei uma foto de papel amassado. A cor vem dos retângulos semitransparentes por cima, então a textura pode ser cinza mesmo.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/textura_papel.png" class="img-fluid figure-img" style="width:60.0%"></p>
<figcaption>A textura de papel amassado que vai no fundo.</figcaption>
</figure>
</div>
</section>
<section id="passo-1-ler-e-preparar-os-dados" class="level2">
<h2 data-anchor-id="passo-1-ler-e-preparar-os-dados">Passo 1: ler e preparar os dados</h2>
<p>Primeiro, os pacotes e a fonte. Se a OCR A Std não estiver instalada, o código usa uma fonte monoespaçada no lugar, para o gráfico não quebrar:</p>
<div class="cell">
<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;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(janitor)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(treemapify)</span>
<span id="cb2-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(png)</span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(grid)</span>
<span id="cb2-6"></span>
<span id="cb2-7">fonte <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OCR A Std"</span></span>
<span id="cb2-8"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>fonte <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> systemfonts<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;">system_fonts</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>family) fonte <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mono"</span></span></code></pre></div>
</div>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Sobre o <code>extrafont</code>
</div>
</div>
<div class="callout-body-container callout-body">
<p>Na primeira versão eu usava o <code>extrafont</code>, que exige rodar <code>font_import()</code>. Essa função varre todas as fontes do computador e demora vários minutos. Com o <code>ragg</code> como dispositivo gráfico, o R encontra as fontes do sistema sozinho, e o <code>extrafont</code> deixa de ser necessário.</p>
</div>
</div>
<p>Depois, leio o CSV e padronizo os nomes das colunas com <code>clean_names()</code>, que deixa tudo minúsculo e sem acento (<code>SHOW</code> vira <code>show</code>, <code>MÊS</code> vira <code>mes</code>):</p>
<div class="cell">
<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">shows <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;">"data.csv"</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;">clean_names</span>() <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;">filter</span>(<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;">is.na</span>(show)) <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;">mutate</span>(</span>
<span id="cb3-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Evita que "McFly" e "MCFLY " virem dois artistas diferentes</span></span>
<span id="cb3-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_squish</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_to_upper</span>(show)),</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">internacional =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_squish</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_to_upper</span>(internacional)),</span>
<span id="cb3-8">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Marca os favoritos com um asterisco antes do ano</span></span>
<span id="cb3-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ano =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(fav <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;">"SIM"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span>, ano), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(ano))</span>
<span id="cb3-10">  )</span>
<span id="cb3-11"></span>
<span id="cb3-12">shows <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(show, ano, internacional, fav) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 4
  show                          ano   internacional fav  
  &lt;chr&gt;                         &lt;chr&gt; &lt;chr&gt;         &lt;chr&gt;
1 MÓVEIS COLONIAIS DE ACAJU     2013  NACIONAL      NÃO  
2 VESPAS MANDARINAS             2014  NACIONAL      NÃO  
3 TIAGO IORC                    2014  NACIONAL      NÃO  
4 TULIPA RUIZ                   2015  NACIONAL      NÃO  
5 VIVENDO DO ÓCIO               2015  NACIONAL      NÃO  
6 A BANDA MAIS BONITA DA CIDADE 2015  NACIONAL      NÃO  </code></pre>
</div>
</div>
<p>O <code>filter(!is.na(show))</code> descarta linhas vazias, que aparecem quando a planilha tem uma linha em branco no fim.</p>
<p>A limpeza do <code>show</code> parece detalhe, mas faz diferença. Nas minhas primeiras versões apareciam dois retângulos de Far From Alaska, Menores Atos e Francisco, El Hombre, porque um espaço sobrando na planilha basta para o R achar que são artistas diferentes.</p>
<p>O truque do asterisco resolve o “favorito” sem precisar de outra cor ou ícone: ele vira parte do texto do ano e aparece sozinho no gráfico.</p>
</section>
<section id="passo-2-agrupar-por-artista" class="level2">
<h2 data-anchor-id="passo-2-agrupar-por-artista">Passo 2: agrupar por artista</h2>
<p>O treemap precisa de uma linha por artista, então eu agrupo e conto. Os anos são colados em um texto só, um por linha (<code>\n</code>), para empilhar no canto do retângulo:</p>
<div class="cell">
<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">artistas <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> shows <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;">arrange</span>(show, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(ano, <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># anos em ordem, ignorando o asterisco</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(show, internacional) <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;">summarise</span>(</span>
<span id="cb5-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantidade =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb5-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">anos =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(ano, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb5-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb5-8">  )</span>
<span id="cb5-9"></span>
<span id="cb5-10">artistas <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(quantidade)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 4
  show                       internacional quantidade anos                      
  &lt;chr&gt;                      &lt;chr&gt;              &lt;int&gt; &lt;chr&gt;                     
1 MAGLORE                    NACIONAL              13 "2015\n2015\n2016\n2017\n…
2 VANGUART                   NACIONAL              11 "2015\n2016\n2016\n2016\n…
3 SUPERCOMBO                 NACIONAL               9 "2015\n*2015\n2015\n2016\…
4 O TERNO                    NACIONAL               7 "2016\n*2016\n2016\n2017\…
5 RUBEL                      NACIONAL               7 "2016\n*2017\n2018\n2018\…
6 SELVAGENS À PROCURA DE LEI NACIONAL               6 "2016\n2016\n2017\n2018\n…</code></pre>
</div>
</div>
<p>São 317 shows de 167 artistas. Duas observações:</p>
<ul>
<li>O <code>.groups = "drop"</code> desfaz o agrupamento no fim. Sem ele, o resultado continua agrupado por <code>show</code> e o R solta um aviso.</li>
<li>Como agrupo por <code>show</code> <strong>e</strong> <code>internacional</code>, se o mesmo artista estiver marcado de um jeito numa linha e de outro em outra, ele vira dois retângulos. Foi o que aconteceu com McFly numa das versões: um azul (2022) e um bege (2024). Esta conferência lista os casos:</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">artistas <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(show) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 0 × 2
# ℹ 2 variables: show &lt;chr&gt;, n &lt;int&gt;</code></pre>
</div>
</div>
<p>Se a tabela vier vazia, está tudo certo.</p>
</section>
<section id="passo-3-o-treemap-básico" class="level2">
<h2 data-anchor-id="passo-3-o-treemap-básico">Passo 3: o treemap básico</h2>
<p>Com os dados prontos, o treemap em si são três camadas: os retângulos, o nome do artista e os anos.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(artistas, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area =</span> quantidade, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> internacional, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subgroup =</span> anos)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_treemap</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_treemap_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> show), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">place =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"topleft"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_treemap_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> anos), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">place =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottomright"</span>)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/index_files/figure-html/basico-1.png" class="img-fluid figure-img" width="1152"></p>
</figure>
</div>
</div>
</div>
<ul>
<li><code>area</code> define o tamanho de cada retângulo.</li>
<li><code>fill</code> define a cor.</li>
<li><code>place</code> posiciona cada texto: nome em cima à esquerda, anos embaixo à direita.</li>
</ul>
<p>O <code>subgroup = anos</code> merece explicação. O <code>treemapify</code> primeiro agrupa os retângulos por subgrupo e só depois distribui cada grupo no espaço. Como o subgrupo é o texto dos anos, artistas com exatamente os mesmos anos ficam juntos. É por isso que os internacionais que vi uma vez só em 2022 formam um bloco azul, e os shows de 2024 aparecem lado a lado.</p>
<p>Isso tem um efeito colateral: quando acrescentei os asteriscos dos favoritos, textos como “2023” viraram “*2023”, os grupos mudaram e o layout inteiro se reorganizou. Se você preferir um layout que só dependa da quantidade de shows, é só tirar o <code>subgroup</code>.</p>
</section>
<section id="passo-4-o-estilo" class="level2">
<h2 data-anchor-id="passo-4-o-estilo">Passo 4: o estilo</h2>
<p>Aqui o gráfico deixa de ser padrão do ggplot e ganha cara de ingresso velho. São quatro ingredientes.</p>
<p><strong>1. A textura de papel.</strong> Carrego o PNG e transformo num objeto gráfico com <code>rasterGrob()</code>. Depois, <code>annotation_custom()</code> estica a imagem por todo o painel; os limites <code>-Inf</code> e <code>Inf</code> significam “de ponta a ponta”:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">textura <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;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"textura_papel.png"</span>)</span>
<span id="cb10-2">fundo <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;">rasterGrob</span>(textura, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>))</span></code></pre></div>
</div>
<p>A ordem importa: o <code>annotation_custom()</code> tem que vir <strong>antes</strong> do <code>geom_treemap()</code>, senão a textura cobre os retângulos.</p>
<p><strong>2. Retângulos semitransparentes.</strong> Com <code>alpha = 0.9</code>, as dobras do papel aparecem através da cor. A borda branca grossa (<code>colour = "white"</code>, <code>size = 4</code>) separa os artistas como se fossem ingressos recortados.</p>
<p><strong>3. Cores suaves.</strong> Bege e azul-claro, definidos à mão com <code>scale_fill_manual()</code>.</p>
<p><strong>4. A fonte OCR.</strong> Ela entra no <code>family</code> de cada texto. O <code>reflow = TRUE</code> quebra nomes longos em várias linhas, e o <code>min.size</code> define o menor tamanho permitido: abaixo disso, o texto some em vez de ficar ilegível.</p>
<p>Por fim, <code>theme_void()</code> remove eixos e grade, e <code>labs()</code> coloca título, subtítulo e crédito. Escondi a legenda (<code>legend.position = "none"</code>) e expliquei as cores no subtítulo, porque a legenda padrão quebrava o visual.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">grafico <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;">ggplot</span>(</span>
<span id="cb11-2">  artistas,</span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">area =</span> quantidade, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> internacional, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subgroup =</span> anos)</span>
<span id="cb11-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_custom</span>(fundo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_treemap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_treemap_text</span>(</span>
<span id="cb11-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> show),</span>
<span id="cb11-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">place =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"topleft"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reflow =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</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;">min.size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb11-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> fonte, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span></span>
<span id="cb11-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_treemap_text</span>(</span>
<span id="cb11-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> anos),</span>
<span id="cb11-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">place =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottomright"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reflow =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min.size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb11-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> fonte, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span></span>
<span id="cb11-18">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(</span>
<span id="cb11-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</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;">"NACIONAL"</span> <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;">"beige"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"INTERNACIONAL"</span> <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;">"lightblue"</span>)</span>
<span id="cb11-21">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb11-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TODOS OS SHOWS QUE VI DESDE 2013"</span>,</span>
<span id="cb11-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(</span>
<span id="cb11-25">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cada retângulo simboliza um artista que vi ao vivo; sua área é proporcional à quantidade de shows vistos e"</span>,</span>
<span id="cb11-26">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sua cor indica se é um artista nacional ou internacional. Anos com * foram meus shows favoritos"</span>,</span>
<span id="cb11-27">      <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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb11-28">    ),</span>
<span id="cb11-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"@biancmuniz</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Atualizado em: "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.Date</span>(), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%d/%m/%Y"</span>))</span>
<span id="cb11-30">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_void</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(</span>
<span id="cb11-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>,</span>
<span id="cb11-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>),</span>
<span id="cb11-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb11-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> fonte, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>),</span>
<span id="cb11-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> fonte, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>),</span>
<span id="cb11-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.caption =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> fonte, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb11-39">  )</span>
<span id="cb11-40"></span>
<span id="cb11-41">grafico</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/index_files/figure-html/final-1.png" class="img-fluid figure-img" width="2000"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="passo-5-salvar-no-tamanho-certo" class="level2">
<h2 data-anchor-id="passo-5-salvar-no-tamanho-certo">Passo 5: salvar no tamanho certo</h2>
<p>Se você chama <code>ggsave("arquivo.png")</code> sem dizer o tamanho, ele usa o tamanho da janela de gráficos do RStudio naquele momento. Como o treemap preenche qualquer espaço que receber, o layout muda junto com a janela.</p>
<p>A solução é fixar largura, altura e resolução, e usar o <code>ragg</code> para que a fonte apareça no arquivo:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggsave</span>(</span>
<span id="cb12-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"shows.png"</span>, grafico,</span>
<span id="cb12-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dpi =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb12-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">device =</span> ragg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>agg_png, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bg =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span></span>
<span id="cb12-5">)</span></code></pre></div>
</div>
<p>Isso gera uma imagem de 2000 × 1050 pixels, no formato horizontal que funciona bem em post e tela de computador.</p>
</section>
<section id="o-que-deu-errado-no-caminho" class="level2">
<h2 data-anchor-id="o-que-deu-errado-no-caminho">O que deu errado no caminho</h2>
<p>O gráfico final foi a sexta ou sétima tentativa. Estes foram os tropeços, na ordem em que aconteceram.</p>
<section id="a-ideia-dos-ícones-de-ingresso" class="level3">
<h3 data-anchor-id="a-ideia-dos-ícones-de-ingresso">A ideia dos ícones de ingresso</h3>
<p>Antes de chegar na textura, eu queria colocar um ícone de ticket ou um código de barras dentro de cada retângulo.</p>
<div>

</div>
<div class="quarto-layout-panel" data-layout-ncol="3">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 33.3%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/icone-codigo-barras.png" class="img-fluid figure-img" width="200"></p>
<figcaption>Código de barras</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell" style="flex-basis: 33.3%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/icone-ingresso-cor.png" class="img-fluid figure-img" width="80"></p>
<figcaption>Ingresso colorido</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell" style="flex-basis: 33.3%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/icone-ingresso.png" class="img-fluid figure-img" width="80"></p>
<figcaption>Ingresso em linha</figcaption>
</figure>
</div>
</div>
</div>
</div>
</section>
<section id="versão-1-todos-os-artistas-que-vi-ao-vivo" class="level3">
<h3 data-anchor-id="versão-1-todos-os-artistas-que-vi-ao-vivo">Versão 1: “Todos os artistas que vi ao vivo”</h3>
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/v1-todos-os-artistas.png" class="img-fluid"></p>
<p>A primeira versão completa já tinha a textura e a fonte. Mas repare em <strong>Far From Alaska</strong>, <strong>Menores Atos</strong>, <strong>Francisco, El Hombre</strong> e <strong>IZA</strong>: cada um aparece duas vezes, porque o nome estava digitado de jeitos diferentes na planilha. Também não havia como saber quais shows foram especiais. A correção foi o <code>str_squish(str_to_upper(show))</code> do Passo 1.</p>
</section>
<section id="versão-2-ajustes-de-texto" class="level3">
<h3 data-anchor-id="versão-2-ajustes-de-texto">Versão 2: ajustes de texto</h3>
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/v2-ajuste-texto.png" class="img-fluid"></p>
<p>Aqui eu só mexi no tamanho e na quebra dos nomes, para caberem melhor nos retângulos pequenos. As duplicatas continuavam lá.</p>
</section>
<section id="versão-3-os-favoritos" class="level3">
<h3 data-anchor-id="versão-3-os-favoritos">Versão 3: os favoritos</h3>
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/v3-favoritos.png" class="img-fluid"></p>
<p>Com o asterisco nos anos favoritos, o layout inteiro mudou de lugar: Vanguart, que estava no meio, foi para o canto superior esquerdo. Demorei para entender que era o <code>subgroup = anos</code> reagrupando os artistas (Passo 3). Gostei do resultado e mantive. Esta é a versão mais próxima da final.</p>
</section>
<section id="versão-4-fonte-grande-demais" class="level3">
<h3 data-anchor-id="versão-4-fonte-grande-demais">Versão 4: fonte grande demais</h3>
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/v4-fonte-grande.png" class="img-fluid"></p>
<p>Aumentei os textos para ficarem mais legíveis, e o subtítulo passou da borda da imagem (“proporcional à quantidade de shows v…”). Os nomes também começaram a se sobrepor aos anos, como em “THE ALL AMERICAN REJECTS”. Voltei aos tamanhos anteriores.</p>
</section>
<section id="versão-5-comprida-e-fina" class="level3">
<h3 data-anchor-id="versão-5-comprida-e-fina">Versão 5: comprida e fina</h3>
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/v5-comprida.png" class="img-fluid" style="width:50.0%"></p>
<p>Salvei com <code>ggsave()</code> sem informar o tamanho, e a janela de gráficos do RStudio estava estreita naquele momento. O treemap obedeceu e virou uma tira vertical. A correção foi fixar <code>width</code>, <code>height</code> e <code>dpi</code> (Passo 5).</p>
</section>
<section id="versão-6-quadrada-e-em-arial" class="level3">
<h3 data-anchor-id="versão-6-quadrada-e-em-arial">Versão 6: quadrada e em Arial</h3>
<p><img src="https://biamuniz.github.io/300em30/blog/posts/treemap-shows/img/v6-quadrada.png" class="img-fluid" style="width:70.0%"></p>
<p>Mesmo problema de tamanho, desta vez num formato quadrado. E o título e o subtítulo saíram em Arial: o dispositivo usado para salvar não encontrou a fonte OCR. A correção foi usar o <code>ragg</code> como dispositivo.</p>
</section>
<section id="a-lição" class="level3">
<h3 data-anchor-id="a-lição">A lição</h3>
<p>Num treemap, tudo depende do espaço disponível. Fixe o tamanho de saída cedo, antes de ajustar fontes e margens, senão você ajusta para uma janela e salva em outra.</p>


</section>
</section>

 ]]></description>
  <category>Análise</category>
  <category>ggplot2</category>
  <guid>https://biamuniz.github.io/300em30/blog/posts/treemap-shows/</guid>
  <pubDate>Tue, 03 Nov 2026 03:00:00 GMT</pubDate>
</item>
</channel>
</rss>
