Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to update a lattice panel in R?
    primarykey
    data
    text
    <p>The <code>update</code> method of <code>trellis</code> plots allows one to modify a <code>lattice</code> plot after the initial call. But the <code>update</code> behaviour is more like replace than append. This differs from the <code>ggplot2</code> idiom where each new layer is additive to what exists already. Is it possible to get this additive behaviour using <code>lattice</code>?</p> <p>An example:</p> <pre><code>LL &lt;- barchart(yield ~ variety | site, data = barley, groups = year, stack = TRUE, between=list(y=0.5), scales = list(x = list(rot = 90))) print(LL) </code></pre> <p><img src="https://i.stack.imgur.com/hpyYz.png" alt="enter image description here"></p> <p>Now I want to add <code>panel.text</code> to the existing plot. Using <code>update</code> in the following way doesn't work:</p> <pre><code>update(LL, panel=function(...){ args &lt;- list(...); panel.text(args$x, args$y+2, round(args$y, 0)) }) </code></pre> <p><img src="https://i.stack.imgur.com/dtmAc.png" alt="enter image description here"></p> <p>I know that I can use <code>update</code> by specifying all of the layers in the panel function:</p> <pre><code>update(LL, panel=function(...){ args &lt;- list(...) panel.barchart(...) panel.text(args$x, args$y+2, round(args$y, 0)) }) </code></pre> <p>This will work, but requires that I know what is already in the <code>lattice</code> plot - or that I refactor my code quite substantially.</p> <p><strong>Question:</strong> Is there a way of adding to the existing panel in <code>update.trellis</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload