<!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>Plot density of mouse positions across time steps. — mt_plot_riverbed • mousetrap</title><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" 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="Plot density of mouse positions across time steps. — mt_plot_riverbed"><meta property="og:description" content="mt_plot_riverbed creates a plot showing the distribution of one
trajectory variable (e.g., the x-positions or velocity) per time step."><!-- 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-reference-topic">
      <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">mousetrap</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">3.2.3</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav"><li>
  <a href="../reference/mousetrap-package.html">Overview</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li>
  <a href="../news/index.html">News</a>
</li>
      </ul><ul class="nav navbar-nav navbar-right"><li>
  <a href="https://github.com/pascalkieslich/mousetrap" class="external-link">
    <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">
    <h1>Plot density of mouse positions across time steps.</h1>
    <small class="dont-index">Source: <a href="https://github.com/pascalkieslich/mousetrap/blob/HEAD/R/riverbed.R" class="external-link"><code>R/riverbed.R</code></a></small>
    <div class="hidden name"><code>mt_plot_riverbed.Rd</code></div>
    </div>

    <div class="ref-description">
    <p><code>mt_plot_riverbed</code> creates a plot showing the distribution of one
trajectory variable (e.g., the x-positions or velocity) per time step.</p>
    </div>

    <div id="ref-usage">
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">mt_plot_riverbed</span><span class="op">(</span></span>
<span>  <span class="va">data</span>,</span>
<span>  use <span class="op">=</span> <span class="st">"tn_trajectories"</span>,</span>
<span>  y <span class="op">=</span> <span class="st">"xpos"</span>,</span>
<span>  y_range <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  y_bins <span class="op">=</span> <span class="fl">250</span>,</span>
<span>  facet_row <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  facet_col <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  facet_data <span class="op">=</span> <span class="st">"data"</span>,</span>
<span>  grid_colors <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"gray30"</span>, <span class="st">"gray10"</span><span class="op">)</span>,</span>
<span>  na.rm <span class="op">=</span> <span class="cn">FALSE</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div id="arguments">
    <h2>Arguments</h2>
    <dl><dt>data</dt>
<dd><p>mousetrap data object containing the data to be plotted.</p></dd>


<dt>use</dt>
<dd><p>character string specifying the set of trajectories to use in the
plot. The steps of this set will constitute the x axis. Defaults to
'tn_trajectories', which results in time steps being plotted on the x axis.</p></dd>


<dt>y</dt>
<dd><p>variable in the mousetrap data object to be plotted on the
output's y dimension. Defaults to 'xpos', the cursor's x coordinate.</p></dd>


<dt>y_range</dt>
<dd><p>numerical vector containing two values that represent the
upper and lower ends of the y axis. By default, the range is calculated
from the data provided.</p></dd>


<dt>y_bins</dt>
<dd><p>number of bins to distribute along the y axis (defaults to
250).</p></dd>


<dt>facet_row</dt>
<dd><p>an optional character string specifying a variable in
<code>data[[facet_data]]</code> that should be used for (row-wise) faceting. If
specified, separate riverbed plots for each level of the variable will be
created.</p></dd>


<dt>facet_col</dt>
<dd><p>an optional character string specifying a variable in
<code>data[[facet_data]]</code> that should be used for (column-wise) faceting.
If specified, separate riverbed plots for each level of the variable will
be created.</p></dd>


<dt>facet_data</dt>
<dd><p>a character string specifying where the (optional) data
containing the faceting variables can be found.</p></dd>


<dt>grid_colors</dt>
<dd><p>a character string or vector of length 2 specifying the
grid color(s). If a single value is provided, this will be used as the grid
color. If a vector of length 2 is provided, the first value will be used as
the color for the major grid lines, the second value for the minor grid
lines. If set to <code>NA</code>, no grid lines are plotted.</p></dd>


<dt>na.rm</dt>
<dd><p>logical specifying whether missing values should be removed.
This is not done by default, because generally riverbed plots are generated
from preprocess trajectories (e.g., time-normalized trajectories) that all
have the same length (i.e., the same number of steps).</p></dd>

</dl></div>
    <div id="details">
    <h2>Details</h2>
    <p>This function plots the relative frequency of the values of a trajectory
variable separately for each of a series of time steps. This type of plot has
been used in previous research to visualize the distribution of x-positions
per time step (e.g., Scherbaum et al., 2010).</p>
<p><code>mt_plot_riverbed</code> usually is applied to time-normalized trajectory data
as all trajectories must contain the same number of values (if
<code>na.rm=FALSE</code>, the default).</p>
    </div>
    <div id="references">
    <h2>References</h2>
    <p>Scherbaum, S., Dshemuchadse, M., Fischer, R., &amp; Goschke, T.
(2010). How decisions evolve: The temporal dynamics of action selection.
<em>Cognition, 115</em>(3), 407-416.</p>
<p>Scherbaum, S., &amp; Kieslich, P. J. (2018). Stuck at the starting line: How
the starting procedure influences mouse-tracking data. <em>Behavior
Research Methods, 50</em>(5), 2097–2110.</p>
    </div>
    <div id="see-also">
    <h2>See also</h2>
    <div class="dont-index"><p><a href="mt_plot.html">mt_plot</a> for plotting trajectory data.</p>
<p><a href="mt_time_normalize.html">mt_time_normalize</a> for time-normalizing trajectories.</p></div>
    </div>
    <div id="author">
    <h2>Author</h2>
    <p>Felix Henninger</p>
<p>Pascal J. Kieslich</p>
    </div>

    <div id="ref-examples">
    <h2>Examples</h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co"># Time-normalize trajectories</span></span></span>
<span class="r-in"><span><span class="va">KH2017</span> <span class="op">&lt;-</span> <span class="fu"><a href="mt_time_normalize.html">mt_time_normalize</a></span><span class="op">(</span><span class="va">KH2017</span><span class="op">)</span></span></span>
<span class="r-in"><span>  </span></span>
<span class="r-in"><span><span class="co"># Create riverbed plot for all trials</span></span></span>
<span class="r-in"><span><span class="fu">mt_plot_riverbed</span><span class="op">(</span><span class="va">KH2017</span><span class="op">)</span></span></span>
<span class="r-plt img"><img src="mt_plot_riverbed-1.png" alt="" width="700" height="433"></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="cn">FALSE</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span><span class="co"># Create separate plots for typical and atypical trials</span></span></span>
<span class="r-in"><span><span class="fu">mt_plot_riverbed</span><span class="op">(</span><span class="va">mt_example</span>, facet_col<span class="op">=</span><span class="st">"Condition"</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Create riverbed plot for all trials with custom x and y axis labels</span></span></span>
<span class="r-in"><span><span class="fu">mt_plot_riverbed</span><span class="op">(</span><span class="va">mt_example</span><span class="op">)</span> <span class="op">+</span></span></span>
<span class="r-in"><span>  <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">xlab</a></span><span class="op">(</span><span class="st">"Time step"</span><span class="op">)</span> <span class="op">+</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">ylab</a></span><span class="op">(</span><span class="st">"X coordinate"</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Note that it is also possible to replace the</span></span></span>
<span class="r-in"><span><span class="co"># default scale for fill with a custom scale</span></span></span>
<span class="r-in"><span><span class="fu">mt_plot_riverbed</span><span class="op">(</span><span class="va">mt_example</span>, facet_col<span class="op">=</span><span class="st">"Condition"</span><span class="op">)</span> <span class="op">+</span></span></span>
<span class="r-in"><span>  <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_gradient.html" class="external-link">scale_fill_gradientn</a></span><span class="op">(</span>colours<span class="op">=</span><span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/palettes.html" class="external-link">heat.colors</a></span><span class="op">(</span><span class="fl">9</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>    name<span class="op">=</span><span class="st">"Frequency"</span>, trans<span class="op">=</span><span class="st">"log"</span>, labels<span class="op">=</span><span class="fu">scales</span><span class="fu">::</span><span class="va"><a href="https://scales.r-lib.org/reference/percent_format.html" class="external-link">percent</a></span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
    <nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
    </nav></div>
</div>


      <footer><div class="copyright">
  <p></p><p>Developed by Pascal J. Kieslich, Dirk U. Wulff, Felix Henninger, Jonas M. B. Haslbeck.</p>
</div>

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

      </footer></div>

  


  

  </body></html>

