visualizeR/reference/bar.html

248 lines
15 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, shrink-to-fit=no"><title>Simple bar chart — hbar • visualizeR</title><!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png"><link rel="icon" type="”image/svg+xml”" href="../favicon.svg"><link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"><link rel="icon" sizes="any" href="../favicon.ico"><link rel="manifest" href="../site.webmanifest"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Simple bar chart — hbar"><meta name="description" content="`bar()` is a simple bar chart with some customization allowed, in particular the `theme_fun` argument for theming. `hbar()` uses `bar()` with sane defaults for a horizontal bar chart."><meta property="og:description" content="`bar()` is a simple bar chart with some customization allowed, in particular the `theme_fun` argument for theming. `hbar()` uses `bar()` with sane defaults for a horizontal bar chart."><meta property="og:image" content="https://gnoblet.github.io/visualizeR/logo.png"></head><body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">
<a class="navbar-brand me-2" href="../index.html">visualizeR</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.0</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
<ul class="navbar-nav me-auto"><li class="active nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="nav-item dropdown">
<button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
<ul class="dropdown-menu" aria-labelledby="dropdown-articles"><li><a class="dropdown-item" href="../articles/bar_charts.html">Bar charts</a></li>
</ul></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
</ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
<input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/gnoblet/visualizeR/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
</ul></div>
</div>
</nav><div class="container template-reference-topic">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.png" class="logo" alt=""><h1>Simple bar chart</h1>
<small class="dont-index">Source: <a href="https://github.com/gnoblet/visualizeR/blob/main/R/bar.R" class="external-link"><code>R/bar.R</code></a></small>
<div class="d-none name"><code>bar.Rd</code></div>
</div>
<div class="ref-description section level2">
<p>`bar()` is a simple bar chart with some customization allowed, in particular the `theme_fun` argument for theming. `hbar()` uses `bar()` with sane defaults for a horizontal bar chart.</p>
</div>
<div class="section level2">
<h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">hbar</span><span class="op">(</span></span>
<span> <span class="va">...</span>,</span>
<span> flip <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> add_text <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> theme_fun <span class="op">=</span> <span class="fu"><a href="theme_default.html">theme_bar</a></span><span class="op">(</span>flip <span class="op">=</span> <span class="va">flip</span>, add_text <span class="op">=</span> <span class="va">add_text</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="fu">bar</span><span class="op">(</span></span>
<span> <span class="va">df</span>,</span>
<span> <span class="va">x</span>,</span>
<span> <span class="va">y</span>,</span>
<span> group <span class="op">=</span> <span class="st">""</span>,</span>
<span> facet <span class="op">=</span> <span class="st">""</span>,</span>
<span> order <span class="op">=</span> <span class="st">"none"</span>,</span>
<span> x_rm_na <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> y_rm_na <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> group_rm_na <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> facet_rm_na <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> y_expand <span class="op">=</span> <span class="fl">0.1</span>,</span>
<span> add_color <span class="op">=</span> <span class="fu"><a href="color.html">color</a></span><span class="op">(</span><span class="st">"cat_5_main_1"</span><span class="op">)</span>,</span>
<span> add_color_guide <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> flip <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> wrap <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> position <span class="op">=</span> <span class="st">"dodge"</span>,</span>
<span> alpha <span class="op">=</span> <span class="fl">1</span>,</span>
<span> x_title <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> y_title <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> group_title <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> title <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> subtitle <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> caption <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> width <span class="op">=</span> <span class="fl">0.8</span>,</span>
<span> add_text <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> add_text_size <span class="op">=</span> <span class="fl">4.5</span>,</span>
<span> add_text_color <span class="op">=</span> <span class="fu"><a href="color.html">color</a></span><span class="op">(</span><span class="st">"dark_grey"</span><span class="op">)</span>,</span>
<span> add_text_font_face <span class="op">=</span> <span class="st">"bold"</span>,</span>
<span> add_text_threshold_display <span class="op">=</span> <span class="fl">0.05</span>,</span>
<span> add_text_suffix <span class="op">=</span> <span class="st">"%"</span>,</span>
<span> add_text_expand_limit <span class="op">=</span> <span class="fl">1.2</span>,</span>
<span> add_text_round <span class="op">=</span> <span class="fl">1</span>,</span>
<span> theme_fun <span class="op">=</span> <span class="fu"><a href="theme_default.html">theme_bar</a></span><span class="op">(</span>flip <span class="op">=</span> <span class="va">flip</span>, add_text <span class="op">=</span> <span class="va">add_text</span>, axis_text_x_angle <span class="op">=</span> <span class="fl">0</span>,</span>
<span> axis_text_x_vjust <span class="op">=</span> <span class="fl">0.5</span>, axis_text_x_hjust <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span>,</span>
<span> scale_fill_fun <span class="op">=</span> <span class="fu"><a href="scale_color_visualizer_discrete.html">scale_fill_visualizer_discrete</a></span><span class="op">(</span><span class="op">)</span>,</span>
<span> scale_color_fun <span class="op">=</span> <span class="fu"><a href="scale_color_visualizer_discrete.html">scale_color_visualizer_discrete</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
<dl><dt id="arg-flip">flip<a class="anchor" aria-label="anchor" href="#arg-flip"></a></dt>
<dd><p>TRUE or FALSE (default). Default to TRUE or horizontal bar plot.</p></dd>
<dt id="arg-add-text">add_text<a class="anchor" aria-label="anchor" href="#arg-add-text"></a></dt>
<dd><p>TRUE or FALSE. Add values as text.</p></dd>
<dt id="arg-theme-fun">theme_fun<a class="anchor" aria-label="anchor" href="#arg-theme-fun"></a></dt>
<dd><p>Whatever theme function. For no custom theme, use theme_fun = NULL.</p></dd>
<dt id="arg-df">df<a class="anchor" aria-label="anchor" href="#arg-df"></a></dt>
<dd><p>A data frame.</p></dd>
<dt id="arg-x">x<a class="anchor" aria-label="anchor" href="#arg-x"></a></dt>
<dd><p>A quoted numeric column.</p></dd>
<dt id="arg-y">y<a class="anchor" aria-label="anchor" href="#arg-y"></a></dt>
<dd><p>A quoted character column or coercible as a character column.</p></dd>
<dt id="arg-group">group<a class="anchor" aria-label="anchor" href="#arg-group"></a></dt>
<dd><p>Some quoted grouping categorical column, e.g. administrative areas or population groups.</p></dd>
<dt id="arg-facet">facet<a class="anchor" aria-label="anchor" href="#arg-facet"></a></dt>
<dd><p>Some quoted grouping categorical column, e.g. administrative areas or population groups.</p></dd>
<dt id="arg-order">order<a class="anchor" aria-label="anchor" href="#arg-order"></a></dt>
<dd><p>A character scalar specifying the order type (one of "none", "y", "grouped"). See details.</p></dd>
<dt id="arg-x-rm-na">x_rm_na<a class="anchor" aria-label="anchor" href="#arg-x-rm-na"></a></dt>
<dd><p>Remove NAs in x?</p></dd>
<dt id="arg-y-rm-na">y_rm_na<a class="anchor" aria-label="anchor" href="#arg-y-rm-na"></a></dt>
<dd><p>Remove NAs in y?</p></dd>
<dt id="arg-group-rm-na">group_rm_na<a class="anchor" aria-label="anchor" href="#arg-group-rm-na"></a></dt>
<dd><p>Remove NAs in group?</p></dd>
<dt id="arg-facet-rm-na">facet_rm_na<a class="anchor" aria-label="anchor" href="#arg-facet-rm-na"></a></dt>
<dd><p>Remove NAs in facet?</p></dd>
<dt id="arg-y-expand">y_expand<a class="anchor" aria-label="anchor" href="#arg-y-expand"></a></dt>
<dd><p>Multiplier to expand the y axis.</p></dd>
<dt id="arg-add-color">add_color<a class="anchor" aria-label="anchor" href="#arg-add-color"></a></dt>
<dd><p>Add a color to bars (if no grouping).</p></dd>
<dt id="arg-add-color-guide">add_color_guide<a class="anchor" aria-label="anchor" href="#arg-add-color-guide"></a></dt>
<dd><p>Should a legend be added?</p></dd>
<dt id="arg-wrap">wrap<a class="anchor" aria-label="anchor" href="#arg-wrap"></a></dt>
<dd><p>Should x-labels be wrapped? Number of characters.</p></dd>
<dt id="arg-position">position<a class="anchor" aria-label="anchor" href="#arg-position"></a></dt>
<dd><p>Should the chart be stacked? Default to "dodge". Can take "dodge" and "stack".</p></dd>
<dt id="arg-alpha">alpha<a class="anchor" aria-label="anchor" href="#arg-alpha"></a></dt>
<dd><p>Fill transparency.</p></dd>
<dt id="arg-x-title">x_title<a class="anchor" aria-label="anchor" href="#arg-x-title"></a></dt>
<dd><p>The x scale title. Default to NULL.</p></dd>
<dt id="arg-y-title">y_title<a class="anchor" aria-label="anchor" href="#arg-y-title"></a></dt>
<dd><p>The y scale title. Default to NULL.</p></dd>
<dt id="arg-group-title">group_title<a class="anchor" aria-label="anchor" href="#arg-group-title"></a></dt>
<dd><p>The group legend title. Default to NULL.</p></dd>
<dt id="arg-title">title<a class="anchor" aria-label="anchor" href="#arg-title"></a></dt>
<dd><p>Plot title. Default to NULL.</p></dd>
<dt id="arg-subtitle">subtitle<a class="anchor" aria-label="anchor" href="#arg-subtitle"></a></dt>
<dd><p>Plot subtitle. Default to NULL.</p></dd>
<dt id="arg-caption">caption<a class="anchor" aria-label="anchor" href="#arg-caption"></a></dt>
<dd><p>Plot caption. Default to NULL.</p></dd>
<dt id="arg-width">width<a class="anchor" aria-label="anchor" href="#arg-width"></a></dt>
<dd><p>Bar width.</p></dd>
<dt id="arg-add-text-size">add_text_size<a class="anchor" aria-label="anchor" href="#arg-add-text-size"></a></dt>
<dd><p>Text size.</p></dd>
<dt id="arg-add-text-color">add_text_color<a class="anchor" aria-label="anchor" href="#arg-add-text-color"></a></dt>
<dd><p>Text color.</p></dd>
<dt id="arg-add-text-font-face">add_text_font_face<a class="anchor" aria-label="anchor" href="#arg-add-text-font-face"></a></dt>
<dd><p>Text font_face.</p></dd>
<dt id="arg-add-text-threshold-display">add_text_threshold_display<a class="anchor" aria-label="anchor" href="#arg-add-text-threshold-display"></a></dt>
<dd><p>Minimum value to add the text label.</p></dd>
<dt id="arg-add-text-suffix">add_text_suffix<a class="anchor" aria-label="anchor" href="#arg-add-text-suffix"></a></dt>
<dd><p>If percent is FALSE, should we add a suffix to the text label?</p></dd>
<dt id="arg-add-text-expand-limit">add_text_expand_limit<a class="anchor" aria-label="anchor" href="#arg-add-text-expand-limit"></a></dt>
<dd><p>Default to adding 10% on top of the bar.</p></dd>
<dt id="arg-add-text-round">add_text_round<a class="anchor" aria-label="anchor" href="#arg-add-text-round"></a></dt>
<dd><p>Round the text label.</p></dd>
</dl></div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
<p>Developed by Noblet Guillaume.</p>
</div>
<div class="pkgdown-footer-right">
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.3.</p>
</div>
</footer></div>
</body></html>