<!-- Generated by pkgdown: do not edit by hand --><htmllang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><metaname="description"content="Addalinetoanexistingchart(bar,scatterandlinetypessupported).
On scatter charts you can also add a smooth line."><title>Add a line to a chart — add-line • apexcharter</title><scriptsrc="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><linkhref="../deps/bootstrap-5.1.0/bootstrap.min.css"rel="stylesheet"><scriptsrc="../deps/bootstrap-5.1.0/bootstrap.bundle.min.js"></script><linkhref="../deps/_Poppins-0.4.0/font.css"rel="stylesheet"><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css"integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw="crossorigin="anonymous"><!-- bootstrap-toc --><scriptsrc="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script><!-- headroom.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js"integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js"integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4="crossorigin="anonymous"></script><!-- clipboard.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI="crossorigin="anonymous"></script><!-- search --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js"integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js"integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww=="crossorigin="anonymous"></script><!-- pkgdown --><scriptsrc="../pkgdown.js"></script><metaproperty="og:title"content="Add a line to a chart — add-line"><metaproperty="og:description"content="Addalinetoanexistingchart(bar,scatterandlinetypessupported).
On scatter charts you can also add a smooth line."><!-- mathjax --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k="crossorigin="anonymous"></script><scriptsrc="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]>
<![endif]--><!-- dependencies from examples --><scriptsrc="libs/htmlwidgets-1.5.4/htmlwidgets.js"></script><scriptsrc="libs/apexcharter-binding-0.3.1/apexcharter.js"></script></head><body>
data <spanclass="op">=</span><spanclass="cn">NULL</span>,
type <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"line"</span>, <spanclass="st">"spline"</span><spanclass="op">)</span>,
formula <spanclass="op">=</span><spanclass="va">y</span><spanclass="op">~</span><spanclass="va">x</span>,
model <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"lm"</span>, <spanclass="st">"loess"</span><spanclass="op">)</span>,
n <spanclass="op">=</span><spanclass="fl">100</span>,
<spanclass="va">...</span>,
type <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"line"</span>, <spanclass="st">"spline"</span><spanclass="op">)</span>,
<dd><p>Default list of aesthetic mappings to use for chart.</p></dd>
<dt>data</dt>
<dd><p>A <code>data.frame</code> to use to add a line, if <code>NULL</code> (default),
the <code>data.frame</code> provided in <code><ahref="apex.html">apex()</a></code> will be used.</p></dd>
<dt>type</dt>
<dd><p>Type of line.</p></dd>
<dt>serie_name</dt>
<dd><p>Name for the serie displayed in tooltip and legend.</p></dd>
<dt>formula</dt>
<dd><p>Formula passed to the <code>method</code>, default to <code>y ~ x</code> from main aesthetics.</p></dd>
<dt>model</dt>
<dd><p>Model to use between <code><ahref="https://rdrr.io/r/stats/lm.html"class="external-link">lm</a></code> or <code><ahref="https://rdrr.io/r/stats/loess.html"class="external-link">loess</a></code>.</p></dd>
<dt>n</dt>
<dd><p>Number of points used for predictions.</p></dd>
<dt>...</dt>
<dd><p>Arguments passed to <code>model</code>.</p></dd>
<spanclass="r-in"><spanclass="co"># Add a line on a column's chart</span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">climate_paris</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">month</span>, <spanclass="va">precipitation</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"column"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">climate_paris</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">month</span>, <spanclass="va">precipitation</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"column"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"> title <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a></span><spanclass="op">(</span>text <spanclass="op">=</span><spanclass="st">"Precipitation (in mm)"</span><spanclass="op">)</span></span>
<spanclass="r-in"> title <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a></span><spanclass="op">(</span>text <spanclass="op">=</span><spanclass="st">"Temperature (in degree celsius)"</span><spanclass="op">)</span></span>
<scripttype="application/json"data-for="htmlwidget-639a0cb550cff143616f">{"x":{"ax_opts":{"chart":{"type":"line"},"series":[{"name":"precipitation","type":"bar","data":[{"x":"Jan","y":53.7},{"x":"Feb","y":43.7},{"x":"Mar","y":48.5},{"x":"Apr","y":53},{"x":"May","y":65},{"x":"Jun","y":54.6},{"x":"Jul","y":63.2},{"x":"Aug","y":43},{"x":"Sep","y":54.7},{"x":"Oct","y":59.7},{"x":"Nov","y":52},{"x":"Dec","y":58.7}]},{"name":"temperature","type":"line","data":[{"x":"Jan","y":4.7},{"x":"Feb","y":5.5},{"x":"Mar","y":8.4},{"x":"Apr","y":10.8},{"x":"May","y":14.8},{"x":"Jun","y":17.6},{"x":"Jul","y":20},{"x":"Aug","y":20},{"x":"Sep","y":16.7},{"x":"Oct","y":12.6},{"x":"Nov","y":7.9},{"x":"Dec","y":5.7}]}],"dataLabels":{"enabled":true,"enabledOnSeries":[1]},"plotOptions":{"bar":{"horizontal":false}},"tooltip":{"shared":true,"intersect":false,"followCursor":true},"xaxis":{"labels":{"style":{"colors":"#848484"}}},"stroke":{"width":[0,4],"curve":"straight"},"yaxis":[{"labels":{"style":{"colors":"#848484"}},"title":{"text":"Precipitation (in mm)"}},{"opposite":true,"decimalsInFloat":0,"title":{"text":"Temperature (in degree celsius)"}}]},"auto_update":{"series_animate":true,"update_options":false,"options_animate":true,"options_redrawPaths":true,"update_synced_charts":false},"sparkbox":false,"xaxis":{"min":"Apr","max":"Sep"},"type":"column","mixed_type":"bar"},"evals":[],"jsHooks":[]}</script><spanclass="r-in"></span>
<spanclass="r-in"><spanclass="co"># add smooth line on scatter plot</span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">cars</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">speed</span>, <spanclass="va">dist</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"scatter"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"><spanclass="fu">add_line</span><spanclass="op">(</span><spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">x</span>, <spanclass="va">y</span><spanclass="op">)</span>, data <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/stats/lowess.html"class="external-link">lowess</a></span><spanclass="op">(</span><spanclass="va">cars</span><spanclass="op">)</span>, serie_name <spanclass="op">=</span><spanclass="st">"lowess"</span><spanclass="op">)</span></span>
<spanclass="r-in"><spanclass="co"># or directly</span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">cars</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">speed</span>, <spanclass="va">dist</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"scatter"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">cars</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">speed</span>, <spanclass="va">dist</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"scatter"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">cars</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">speed</span>, <spanclass="va">dist</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"scatter"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">cars</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">speed</span>, <spanclass="va">dist</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"scatter"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
<spanclass="r-in"><spanclass="fu"><ahref="apex.html">apex</a></span><spanclass="op">(</span><spanclass="va">cars</span>, <spanclass="fu"><ahref="apexcharter-exports.html">aes</a></span><spanclass="op">(</span><spanclass="va">speed</span>, <spanclass="va">dist</span><spanclass="op">)</span>, type <spanclass="op">=</span><spanclass="st">"scatter"</span><spanclass="op">)</span><spanclass="op"><ahref="apexcharter-exports.html">%>%</a></span></span>
</main><asideclass="col-md-3"><navid="toc"><h2>On this page</h2>
</nav></aside></div>
<footer><divclass="pkgdown-footer-left">
<p></p><p>Developed by <ahref="https://twitter.com/_pvictorr"class="external-link"><imgsrc="https://pbs.twimg.com/profile_images/844237339404722177/E1U61aM8_normal.jpg"> Victor Perrier</a>, <ahref="https://twitter.com/_mfaan"class="external-link"><imgsrc="https://pbs.twimg.com/profile_images/912313931326218240/o1-wvA18_normal.jpg"> Fanny Meyer</a>.</p>