10

From Plot vectors of different length with ggplot2, I've got my plot with lines.

ggplot(plotData, aes(x, y, label=label, group=label)) + geom_line() + stat_smooth()

But this smooths one line each. How do I smooth over all data points?

Community
  • 1
  • 1
Reactormonk
  • 21,472
  • 14
  • 74
  • 123
  • 2
    I see you've been asking a lot of rather similar questions in the last 24 hours. Perhaps you could benefit from spending a little more time with the R tutorials, such as https://sites.google.com/site/r4statistics/example-programs/graphics-ggplot2 and http://egret.psychol.cam.ac.uk/statistics/R/graphs2.html . – Carl Witthoft Mar 19 '12 at 12:07

1 Answers1

16
ggplot(plotData, aes(x, y, label=label, group=label)) + 
    geom_line() +
    geom_smooth(aes(group = 1))

should do it. The idea here is to provide a new group aesthetic so that the fitted smoother is based on all the data, not the group = label aesthetic.

Following the example from @Andrie's Answer the modification I propose would be:

ggplot(plotData, aes(x, y, label=label, group=label)) + 
    geom_text() + 
    geom_smooth(aes(group = 1))

which would produce:

enter image description here

Community
  • 1
  • 1
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453