mirror of
https://github.com/ryantimpe/brickr.git
synced 2025-12-30 10:19:43 -06:00
246 lines
19 KiB
HTML
246 lines
19 KiB
HTML
<!DOCTYPE html>
|
||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>ggplot with brickr • brickr</title>
|
||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
|
||
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
|
||
<script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||
<meta property="og:title" content="ggplot with brickr">
|
||
<meta property="og:description" content="">
|
||
<meta property="og:image" content="http://brickr.org/logo.png">
|
||
<meta name="twitter:card" content="summary">
|
||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||
<![endif]-->
|
||
</head>
|
||
<body>
|
||
<div class="container template-article">
|
||
<header><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" aria-expanded="false">
|
||
<span class="sr-only">Toggle navigation</span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
</button>
|
||
<span class="navbar-brand">
|
||
<a class="navbar-link" href="../index.html">brickr</a>
|
||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9024</span>
|
||
</span>
|
||
</div>
|
||
|
||
<div id="navbar" class="navbar-collapse collapse">
|
||
<ul class="nav navbar-nav">
|
||
<li>
|
||
<a href="../index.html">
|
||
<span class="fa fa-home fa-lg"></span>
|
||
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../reference/index.html">Reference</a>
|
||
</li>
|
||
<li class="dropdown">
|
||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
|
||
Articles
|
||
|
||
<span class="caret"></span>
|
||
</a>
|
||
<ul class="dropdown-menu" role="menu">
|
||
<li>
|
||
<a href="../articles/graphs.html">ggplot with brickr</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/models-from-other.html">3D Models from mosaics & rayshader</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/models-from-program.html">3D Models programmatically</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/models-from-tables.html">3D models from tables</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/mosaics.html">Mosaics with brickr</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<a href="../news/index.html">Changelog</a>
|
||
</li>
|
||
</ul>
|
||
<ul class="nav navbar-nav navbar-right">
|
||
<li>
|
||
<a href="https://github.com/ryantimpe/brickr">
|
||
<span class="fa fa-github fa-lg"></span>
|
||
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<!--/.nav-collapse -->
|
||
</div>
|
||
<!--/.container -->
|
||
</div>
|
||
<!--/.navbar -->
|
||
|
||
|
||
</header><div class="row">
|
||
<div class="col-md-9 contents">
|
||
<div class="page-header toc-ignore">
|
||
<h1>ggplot with brickr</h1>
|
||
|
||
|
||
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/graphs.Rmd"><code>vignettes/graphs.Rmd</code></a></small>
|
||
<div class="hidden name"><code>graphs.Rmd</code></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<div id="getting-started" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#getting-started" class="anchor"></a>Getting started</h2>
|
||
<p>brickr includes functions to render <a href="https://ggplot2.tidyverse.org/">ggplot2</a> bar charts as bricks with LEGO color themes. The main function is <code><a href="../reference/geom_brick_col.html">geom_brick_col()</a></code>, which is the brickr equivalent of <code>geom_col()</code>. Additional functions are highly recommended to ensure that proper the chart is rendered in the proper functions and proportions.</p>
|
||
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">df <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">trt =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"a"</span>, <span class="st">"b"</span>, <span class="st">"c"</span>), <span class="dt">outcome =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">2.3</span>, <span class="fl">1.9</span>, <span class="fl">3.2</span>))</a>
|
||
<a class="sourceLine" id="cb1-2" title="2"></a>
|
||
<a class="sourceLine" id="cb1-3" title="3"><span class="co">#For official LEGO colors, use with scale_fill_brick and theme_brick.</span></a>
|
||
<a class="sourceLine" id="cb1-4" title="4"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(trt, outcome)) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb1-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> trt)) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb1-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb1-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb1-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>()</a></code></pre></div>
|
||
<p><img src="graphs_files/figure-html/getting_started-1.png" width="384"></p>
|
||
<ul>
|
||
<li>
|
||
<a href="#geoms"><code><a href="../reference/geom_brick_col.html">geom_brick_col()</a></code></a> draws data columns as bricks.</li>
|
||
<li>
|
||
<a href="#scale-and-themes"><code><a href="../reference/scale_fill_brick.html">scale_fill_brick()</a></code></a> is a discrete color scales, rendering columns in LEGO brick colors.</li>
|
||
<li>
|
||
<a href="#coords"><code><a href="../reference/coord-brick.html">coord_brick()</a></code></a> fixes the ratio between brick width and height. Any excess height is rendered as a residual brick without knobs.</li>
|
||
<li>
|
||
<a href="#scale-and-themes"><code><a href="../reference/theme_brick.html">theme_brick()</a></code></a> is a modified version of <code><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html">ggplot2::theme_minimal()</a></code>.</li>
|
||
</ul>
|
||
<p>See sections below for full detail.</p>
|
||
</div>
|
||
<div id="geoms" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#geoms" class="anchor"></a>Geoms</h2>
|
||
<div id="geom_brick_col" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#geom_brick_col" class="anchor"></a>geom_brick_col()</h3>
|
||
<p>Column / bar charts are rendered using the same structure as <code><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html">ggplot2::geom_col()</a></code>, with a few additional inputs.</p>
|
||
<ul>
|
||
<li>
|
||
<code>two_knob = TRUE</code> (the default) renders columns with a width two LEGO knobs, generating 2x4, 2x3, 2x2, and 2x1 knob bricks. Set to <code>FALSE</code> for columns with a width of 1 knob. This is useful when the chart has many columns and you don’t want to lose brick detail.</li>
|
||
<li>
|
||
<code>split_bricks = TRUE</code> breaks columns into individual bricks, up to 4 knobs in length, as well as a residual brick at the top. Set this to <code>FALSE</code> to remove the splits, while retaining the knobs. *<code>min_radius_for_text</code> specifies the lower bound of knob radius (as a percent of the plot view port) required to display the embossed text inside the knobs. This ensures the plot looks clean when there are many columns. Defaults to 0.02.</li>
|
||
<li>
|
||
<code>label</code> is the text to display inside the brick knobs. A maximum of six characters.</li>
|
||
<li>
|
||
<code>label_scale</code> helps to ensure that the text size of the label fits within the knob circumference. When the graphical device is rendered, brickr makes a best guess on the size of the text. This isn’t always the most aesthetic guess, so use <code>label_scale</code> values to adjust the size. Values >1 will increase the size proportional, while values <1 will decrease the size.
|
||
<ul>
|
||
<li>
|
||
<strong>Important</strong> This best guess is calculated in the initial rendering of the chart, so the text will NOT increase in size when using the zoom feature in RStudio. To share charts, it’s best to use <code>ggsave()</code> rather than screen shots.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">df <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">x =</span> LETTERS[<span class="dv">1</span><span class="op">:</span><span class="dv">10</span>], <span class="dt">y =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">2</span><span class="op">:</span><span class="dv">10</span>, <span class="dv">10</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>))</a>
|
||
<a class="sourceLine" id="cb2-2" title="2"></a>
|
||
<a class="sourceLine" id="cb2-3" title="3"><span class="co">#For official LEGO colors, use with scale_fill_brick and theme_brick.</span></a>
|
||
<a class="sourceLine" id="cb2-4" title="4"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb2-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> x), <span class="dt">two_knob =</span> <span class="ot">FALSE</span>, <span class="dt">label =</span> <span class="st">"LEGO"</span>, <span class="dt">label_scale =</span> <span class="fl">0.9</span>) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb2-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb2-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>()</a></code></pre></div>
|
||
<p><img src="graphs_files/figure-html/geom_brick-1.png" width="480"></p>
|
||
</div>
|
||
</div>
|
||
<div id="coords" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#coords" class="anchor"></a>Coords</h2>
|
||
<p>Using <code><a href="../reference/coord-brick.html">coord_brick()</a></code> ensures that bricks are rendered with correct proportions. Unlike other <code>coord_*</code> functions in ggplot, no other inputs are necessary.</p>
|
||
<p>For horizontal bars, use <code><a href="../reference/coord-brick.html">coord_brick_flip()</a></code>.</p>
|
||
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">df <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">x =</span> LETTERS[<span class="dv">1</span><span class="op">:</span><span class="dv">8</span>], <span class="dt">y =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">2</span><span class="op">:</span><span class="dv">10</span>, <span class="dv">8</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>))</a>
|
||
<a class="sourceLine" id="cb3-2" title="2"></a>
|
||
<a class="sourceLine" id="cb3-3" title="3"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb3-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> x), <span class="dt">two_knob =</span> <span class="ot">FALSE</span>) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb3-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb3-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick_flip</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb3-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb3-8" title="8"><span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.position =</span> <span class="st">"none"</span>)</a></code></pre></div>
|
||
<p><img src="graphs_files/figure-html/coord-1.png" width="480"></p>
|
||
</div>
|
||
<div id="scale-and-themes" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#scale-and-themes" class="anchor"></a>Scale and themes</h2>
|
||
<p>There are 41 LEGO brick colors available in brickr. See <code><a href="../reference/build_colors.html">build_colors()</a></code> or <code><a href="https://www.rdocumentation.org/packages/utils/topics/View">View(lego_colors)</a></code> for the complete list. The easiest way to use theme colors with plots are the <code><a href="../reference/scale_fill_brick.html">scale_fill_brick()</a></code> and the <code><a href="../reference/theme_brick.html">theme_brick()</a></code> functions.</p>
|
||
<p>These functions default to using the ‘classic’ LEGO color theme, but can take any of the 21 themes included in brickr.</p>
|
||
<div id="scales" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#scales" class="anchor"></a>Scales</h3>
|
||
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">df <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">x =</span> LETTERS[<span class="dv">1</span><span class="op">:</span><span class="dv">8</span>], <span class="dt">y =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">2</span><span class="op">:</span><span class="dv">10</span>, <span class="dv">8</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>))</a>
|
||
<a class="sourceLine" id="cb4-2" title="2"></a>
|
||
<a class="sourceLine" id="cb4-3" title="3">use_theme <-<span class="st"> "hp"</span></a>
|
||
<a class="sourceLine" id="cb4-4" title="4"></a>
|
||
<a class="sourceLine" id="cb4-5" title="5"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb4-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> x)) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb4-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>(<span class="dt">brick_theme =</span> use_theme) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb4-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb4-9" title="9"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>(<span class="dt">brick_theme =</span> use_theme) <span class="op">+</span></a>
|
||
<a class="sourceLine" id="cb4-10" title="10"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title =</span> use_theme)</a></code></pre></div>
|
||
<p><img src="graphs_files/figure-html/scales-1.png" width="384"></p>
|
||
<p><img src="graphs_files/figure-html/scales2-1.png" width="960"></p>
|
||
</div>
|
||
<div id="themes" class="section level3">
|
||
<h3 class="hasAnchor">
|
||
<a href="#themes" class="anchor"></a>Themes</h3>
|
||
<p>For a complete list of available themes, use <code><a href="../reference/build_themes.html">build_themes()</a></code>.</p>
|
||
<p><img src="graphs_files/figure-html/themes-1.png" width="672"></p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
||
<div id="tocnav">
|
||
<h2 class="hasAnchor">
|
||
<a href="#tocnav" class="anchor"></a>Contents</h2>
|
||
<ul class="nav nav-pills nav-stacked">
|
||
<li><a href="#getting-started">Getting started</a></li>
|
||
<li><a href="#geoms">Geoms</a></li>
|
||
<li><a href="#coords">Coords</a></li>
|
||
<li><a href="#scale-and-themes">Scale and themes</a></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
<footer><div class="copyright">
|
||
<p>Developed by Ryan Timpe.</p>
|
||
</div>
|
||
|
||
<div class="pkgdown">
|
||
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
|
||
</div>
|
||
</footer>
|
||
</div>
|
||
|
||
|
||
|
||
</body>
|
||
</html>
|