Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is that what you are looking for?</p> <pre><code>library(ggplot2) x &lt;- factor(rep(1:10, 100)) y &lt;- rnorm(1000) df &lt;- data.frame(x=x, y=y) ggplot(df, aes(x=x, y=y)) + geom_boxplot() + stat_summary(fun.y=mean, geom="line", aes(group=1)) + stat_summary(fun.y=mean, geom="point") </code></pre> <p><strong>Update:</strong> </p> <p>Some clarification about setting group=1: I think that I found an explanation in Hadley Wickham's book "<a href="http://tinyurl.com/ggplot2-book" rel="noreferrer">ggplot2: Elegant Graphics for Data Analysis</a>". On page 51 he writes:</p> <blockquote> <p>Different groups on different layers.</p> <p>Sometimes we want to plot summaries based on different levels of aggregation. Different layers might have different group aesthetics, so that some display individual level data while others display summaries of larger groups. </p> <p>Building on the previous example, suppose we want to add a single smooth line to the plot just created, based on the ages and heights of all the boys. If we use the same grouping for the smooth that we used for the line, we get the first plot in Figure 4.4.</p> <p>p + geom_smooth(aes(group = Subject), method="lm", se = F)</p> <p>This is not what we wanted; we have inadvertently added a smoothed line for each boy. This new layer needs a different group aesthetic, group = 1, so that the new line will be based on all the data, as shown in the second plot in the figure. The modified layer looks like this: </p> <p>p + geom_smooth(aes(group = 1), method="lm", size = 2, se = F)</p> <p>[...] Using aes(group = 1) in the smooth layer fits a single line of best fit across all boys."</p> </blockquote>
    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