<!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>Gallery: Times Series Missing Data Visualizations â€¢ imputeTS</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.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Gallery: Times Series Missing Data Visualizations">
<meta property="og:description" content="imputeTS">
<meta property="og:image" content="https://SteffenMoritz.github.io/imputeTS/logo.png">
<!-- 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 data-spy="scroll" data-target="#toc">
    <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">imputeTS</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">3.3</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">
    <span class="fas 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" data-bs-toggle="dropdown" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li>
      <a href="../articles/gallery_visualizations.html">Gallery: Times Series Missing Data Visualizations</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/SteffenMoritz/imputeTS/">
    <span class="fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><script src="gallery_visualizations_files/header-attrs-2.16/header-attrs.js"></script><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>Gallery: Times Series Missing Data
Visualizations</h1>
                        <h4 class="author">Steffen Moritz</h4>
            
            <h4 class="date">2022-08-30</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/SteffenMoritz/imputeTS/blob/master/vignettes/gallery_visualizations.Rmd"><code>vignettes/gallery_visualizations.Rmd</code></a></small>
      <div class="hidden name"><code>gallery_visualizations.Rmd</code></div>

    </div>

    
    
<p>There are multiple different plots for (univarate) time series
missing data available in the imputeTS package. These can be grouped in
the following three categories:</p>
<ul>
<li>Getting an Overview (<code>ggplot_na_distribution</code>)</li>
<li>Deeper insights and missing data patterns
(<code>ggplot_na_distribution2</code>,
<code>ggplot_na_gapsize</code>)</li>
<li>Assessing/Exploring imputation results
(<code>ggplot_na_imputations</code>)</li>
</ul>
<p><em>This vignette showcases all of the available visualizations in
the imputeTS package. More information on time series imputation and the
imputeTS package in general can be found in this paper: <a href="https://journal.r-project.org/archive/2017/RJ-2017-009/index.html">imputeTS:
Time Series Missing Value Imputation in R</a>.</em></p>
<div id="getting-a-first-overview-ggplot_na_distribution" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-a-first-overview-ggplot_na_distribution" class="anchor"></a>Getting a first overview (<code>ggplot_na_distribution</code>)</h2>
<p>The best starting point for getting an overview about the missing
data in your (univariate) time series is the
<code><a href="../reference/ggplot_na_distribution.html">ggplot_na_distribution()</a></code> plot. It gives a nice first
overview where in the time series the missing values occur and how they
are distributed. It also already gives a rough impression on how many
missing data are in different intervals of the time series.</p>
<p>Usage is easy: just supply the (univariate) time series to the
function call. Only the time series is needed as input - all additional
parameters are only needed to alter the appearance of the plot.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="st"><a href="https://github.com/SteffenMoritz/imputeTS">"imputeTS"</a></span><span class="op">)</span>
<span class="fu"><a href="../reference/ggplot_na_distribution.html">ggplot_na_distribution</a></span><span class="op">(</span><span class="va">tsAirgap</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-distribution-example1-1.png" width="600" style="display: block; margin: auto;"></p>
<p>It is important to note, that the input itself needs to be
univariate. For data types with multiple variables/columns only use the
column you want to plot as input parameter <code>x</code>. The x-axis
time information can be added with the <code>x_axis_labels</code>
parameter - otherwise the consecutive index of observations in the
series is used as x-axis tick label.</p>
<p>Thus for a data.frame <code>df</code> with multiple columns
<code>df$date</code>, <code>df$value</code>,
<code>df$another_value</code>, <code>df$yet_another_value</code> where
we want to plot <code>df$value</code> with Dates on the x-axis the
required function call would look like this:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/ggplot_na_distribution.html">ggplot_na_distribution</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">df</span><span class="op">$</span><span class="va">value</span>, x_axis_labels <span class="op">=</span> <span class="va">df</span><span class="op">$</span><span class="va">date</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-distribution-example2-1.png" width="600" style="display: block; margin: auto;"></p>
</div>
<div id="detailed-information-about-certain-intervals-ggplot_na_distribution2" class="section level2">
<h2 class="hasAnchor">
<a href="#detailed-information-about-certain-intervals-ggplot_na_distribution2" class="anchor"></a>Detailed information about certain intervals
(<code>ggplot_na_distribution2</code>)</h2>
<p>When a summary for certain time intervals (e. g. weeks) is needed,
the <code><a href="../reference/ggplot_na_distribution2.html">ggplot_na_distribution2()</a></code> plot is useful. It shows the
missing data percentage for each interval as a bar. This kind of summary
plot is also quite useful for very long time series, which would not fit
into the plot window as a lineplot.</p>
<p>Like for <code><a href="../reference/ggplot_na_distribution.html">ggplot_na_distribution()</a></code> only parameter
<code>x</code> (the univariate time series) is mandatory for creating a
plot with <code><a href="../reference/ggplot_na_distribution2.html">ggplot_na_distribution2()</a></code>. With the parameter
<code>interval_size</code> the size of the interval can be changed
(default is a auto calculated interval size that gives a good overall
overview). All other parameters are mostly needed for changing the
appearance of the plot.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/ggplot_na_distribution2.html">ggplot_na_distribution2</a></span><span class="op">(</span><span class="va">tsNH4</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-distribution2-example1-1.png" width="600" style="display: block; margin: auto;"></p>
<p>Alternatively the missing data count for the interval (instead of the
percentages) can be shown. Below is an example with a custom interval
size of 144 and a custom color for the missing data bars. Since the
example data is recorded in 10 minute time steps, a interval_size of 144
means that we are using daily intervals (6 measurements per hour, 24
hours per day, 6*24 = 144).</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/ggplot_na_distribution2.html">ggplot_na_distribution2</a></span><span class="op">(</span><span class="va">tsNH4</span>, measure <span class="op">=</span> <span class="st">"count"</span>, interval_size <span class="op">=</span> <span class="fl">144</span>, color_missing <span class="op">=</span> <span class="st">"gold3"</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-distribution2-example2-1.png" width="600" style="display: block; margin: auto;"></p>
</div>
<div id="insights-about-missing-data-patterns-ggplot_na_gapsize" class="section level2">
<h2 class="hasAnchor">
<a href="#insights-about-missing-data-patterns-ggplot_na_gapsize" class="anchor"></a>Insights about missing data patterns
(<code>ggplot_na_gapsize</code>)</h2>
<p>Often deeper insights about the missing data are quite useful. These
insights can give hints of possible causes of the missing data and an
indication, which imputation algorithms might give good results. The
plot gives an overview about how often different gapsizes (NAs in a row)
occur in the time series.</p>
<p>Only the parameter <code>x</code> (the univariate time series) is
needed as mandatory input. By default the plot shows only the 10 most
often occuring gapsizes. Use parameter <code>limit</code> to increase
this number.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/SteffenMoritz/imputeTS">imputeTS</a></span><span class="op">)</span>
<span class="fu"><a href="../reference/ggplot_na_gapsize.html">ggplot_na_gapsize</a></span><span class="op">(</span><span class="va">tsNH4</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-gapsize-example1-1.png" width="600" style="display: block; margin: auto;"></p>
<p>The plot shows both, the number of occurrence and the resulting NAs
for the respective gapsizes. Resulting NAs can be explained as the
number of NAs a certain gapsize accounts for in total. For example a
gapsize of 3 that occurs 5 times results in 15 NAs overall. The
parameter <code>include_total</code> can be used to change this
behavior. Below is a example of the same plot with specific settings for
<code>limit</code> and <code>include_total</code>.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/SteffenMoritz/imputeTS">imputeTS</a></span><span class="op">)</span>
<span class="fu"><a href="../reference/ggplot_na_gapsize.html">ggplot_na_gapsize</a></span><span class="op">(</span><span class="va">tsNH4</span>, include_total <span class="op">=</span> <span class="cn">F</span>, limit <span class="op">=</span> <span class="fl">15</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-gapsize-example2-1.png" width="600" style="display: block; margin: auto;"></p>
</div>
<div id="evaluate-imputation-results-ggplot_na_imputations" class="section level2">
<h2 class="hasAnchor">
<a href="#evaluate-imputation-results-ggplot_na_imputations" class="anchor"></a>Evaluate imputation results
(<code>ggplot_na_imputations</code>)</h2>
<p>After using imputation functions like <code><a href="../reference/na_kalman.html">na_kalman()</a></code>,
<code><a href="../reference/na_interpolation.html">na_interpolation()</a></code>, <code><a href="../reference/na_seadec.html">na_seadec()</a></code> there is often
the need to get a first impression on how good the algorithm performs.
The <code><a href="../reference/ggplot_na_imputations.html">ggplot_na_imputations()</a></code> plot gives a good impression on
how well the imputed values fit into the original time series.</p>
<p>Mandatory inputs for this function are these two parameters:
<code>x_with_na</code> (the time series as it was before imputation) and
<code>x_with_imputations</code> (the time series without NAs after
imputation).</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/SteffenMoritz/imputeTS">imputeTS</a></span><span class="op">)</span>
<span class="va">imp</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/na_interpolation.html">na_interpolation</a></span><span class="op">(</span><span class="va">tsAirgap</span><span class="op">)</span>
<span class="fu"><a href="../reference/ggplot_na_imputations.html">ggplot_na_imputations</a></span><span class="op">(</span><span class="va">tsAirgap</span>, <span class="va">imp</span><span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-imputations-example1-1.png" width="600" style="display: block; margin: auto;"></p>
<p>In some cases (mostly when performing imputation experiments and
benchmarks) the NAs were only artificially introduced into the original
time series. Which means, there exists a ground truth for the NA values
(the complete time series before introducing the NAs). In this case you
can additionally use the <code>x_with_truth</code> parameter to get a
plot that displays both, the imputations and the ground truth.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/SteffenMoritz/imputeTS">imputeTS</a></span><span class="op">)</span>
<span class="va">imp</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/na_mean.html">na_mean</a></span><span class="op">(</span><span class="va">tsAirgap</span><span class="op">)</span>
<span class="fu"><a href="../reference/ggplot_na_imputations.html">ggplot_na_imputations</a></span><span class="op">(</span>x_with_na <span class="op">=</span> <span class="va">tsAirgap</span>, x_with_imputations <span class="op">=</span> <span class="va">imp</span>, x_with_truth <span class="op">=</span> <span class="va">tsAirgapComplete</span> <span class="op">)</span></code></pre></div>
<p><img src="gallery_visualizations_files/figure-html/ggplot-na-imputations-example2-1.png" width="600" style="display: block; margin: auto;"></p>
</div>
<div id="support" class="section level2">
<h2 class="hasAnchor">
<a href="#support" class="anchor"></a>Support</h2>
<p>If you found a bug or have suggestions, feel free to open an issue on
GitHub or get in contact via steffen.moritz10 at gmail.com.</p>
<blockquote>
<p>All feedback is welcome</p>
</blockquote>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

        <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
    </nav>
</div>

</div>



      <footer><div class="copyright">
  <p>Developed by Steffen Moritz, Sebastian Gatscha.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>

      </footer>
</div>

  


  </body>
</html>
