Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are talking about the space between facets, you can try this (also note that we do not have <code>short_brks</code> and <code>long_brks</code> so I removed those from your example code). <code>grid</code> is required for the <code>unit</code> function.</p> <pre><code>require(ggplot2) require(grid) avtimes3$id &lt;- factor(avtimes3$id) ## create and store plot p &lt;- ggplot(avtimes3, aes(x=trial, y=ttime, colour=id)) + facet_grid(. ~ brk, scales = "free") + geom_point(shape=21, fill="white") + ## remove space between panels opts(panel.margin = unit(0, "lines")) + ylab("Time taken (ms)") + xlab("Trial No.") ## as you had p + stat_smooth(method="loess") </code></pre> <p><img src="https://i.stack.imgur.com/7nWFI.png" alt="scatterplot with loess lines by ID and facet"></p> <pre><code>## only one line per facet p + stat_smooth(method="loess", aes(colour=NULL)) </code></pre> <p><img src="https://i.stack.imgur.com/y05jU.png" alt="scatterplot with loess lines by facet only"></p> <p>Edit: Rereading what you wrote and tried, I think you may want this:</p> <pre><code>## setup plot p &lt;- ggplot(avtimes3, aes(x=trial, y=ttime, colour=id)) + geom_point(shape=21, fill="white") + ylab("Time taken (ms)") + xlab("Trial No.") p + stat_smooth(aes(group = brk), method="loess") </code></pre> <p><img src="https://i.stack.imgur.com/rg7Ux.png" alt="three loess lines on scatterplot no facetting"></p> <p>The here that differs from what you had before is that the first argument to <code>stat_smooth</code> is mapping, the fifth is method. In <code>R</code> you have two options (maybe more). Either give the arguments in order <em>or</em> explicitly name the arguments. In your second example, you gave the arguments out of order and did not name explicitly like:</p> <pre><code>p + stat_smooth(method = "loess", mapping = aes(group = brk)) </code></pre> <p>To get separate lines for each id and grouping by <code>brk</code> is a bit trickier (conceptually). We need the interaction of brk and id. Colouring alone does not work, as it would with most geoms.</p> <pre><code>p + stat_smooth(method = "loess", mapping = aes(group = interaction(brk, id))) </code></pre> <p><img src="https://i.stack.imgur.com/gVQnv.png" alt="scatterplot with loess lines broken down by id and position"></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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