0

I am working through an example creating a faceted plot using ggplot. The plot contains 4 subplots, each with multiple lines. How do you plot the mean line for each of the subplots? My attempt is shown below:

library(datasets)
data(ChickWeight)

library(ggplot2)
g = ggplot(ChickWeight, aes(x = Time, y = weight))
g = g + geom_line(aes(group = Chick, color = Diet))
g = g + facet_grid(. ~ Diet)
g = g + stat_summary(aes(group = Diet), fun.y=mean, size = 1, color="black", geom="line")
g

I am unsure if I am using the geom_summary function correctly. I also tried geom_smooth(method = "lm", se = FALSE) but was unsure whether this output was the same as the mean.

RHA
  • 3,677
  • 4
  • 25
  • 48
Dan A.
  • 129
  • 10
  • Looks correct. If you would like a [Code Review](http://codereview.stackexchange.com/) that site may be better suited to seek comments on the usefulness/efficiency of your code. Stack Overflow is designed for specific programming problems. – Pierre L Dec 08 '16 at 18:41
  • Thank you! I am slowly learning how to properly use this site. – Dan A. Dec 13 '16 at 17:07

0 Answers0