strong difference between geom_line and stat_smooth in ggplot2
<p>I have issues with visualizing my dataset via the geom_line and stat_smooth option. </p>

<p>Here is a example from my dataset which I created by dput: </p>

<pre><code>example_data &lt;- structure(list(treatment1 = c(-1.41, -1.49, -1.6, -1.65, -1.64, 
                                              -1.76, -1.73, -1.55, -1.35, -1.22, -1.36, -1.49, -1.49, -1.45, 
                                              -1.45, -1.43, -1.36, -1.45, -1.31, -1.31, -1.31, -1.19, -0.95, 
                                              -1.07, -1.07, -1.13, -1.1, -1.02, -1.01, -0.9, -0.88, -0.78, 
                                              -0.76, -0.7, -0.6, -0.33, -0.28, -0.25, -0.07, 0.18, 0.21, 0.35, 
                                              0.49, 0.54, 0.8, 1.11, 1.28, 1.41, 1.62, 1.67, 1.62, 1.66, 1.47, 
                                              1.43, 1.23, 1.02, 1.04, 0.91, 0.72, 0.67, 0.53, 0.43, 0.16, -0.04, 
                                              -0.13, -0.12, -0.15, -0.28, -0.49, -0.38, -0.65, -0.83, -0.76, 
                                              -0.76, -0.73, -0.81, -0.85, -0.86, -0.85, -0.97, -0.94, -0.99, 
                                              -1.05, -1.03, -1.01, -1.13, -1.06, -1.07, -1.18, -1.22, -1.34, 
                                              -1.39, -1.39, -1.48, -1.34, -1.46, -1.47), treatment2 = c(-1.36, 
                                                                                                        -1.39, -1.37, -1.34, -1.37, -1.4, -1.38, -1.36, -1.36, -1.35, 
                                                                                                        -1.34, -1.34, -1.32, -1.28, -1.29, -1.28, -1.22, -1.21, -1.2, 
                                                                                                        -1.17, -1.18, -1.16, -1.11, -1.08, -1.06, -1.03, -0.98, -0.95, 
                                                                                                        -0.88, -0.82, -0.77, -0.68, -0.66, -0.56, -0.48, -0.38, -0.3, 
                                                                                                        -0.19, -0.08, 0.08, 0.22, 0.34, 0.5, 0.64, 0.89, 1.18, 1.41, 
                                                                                                        1.52, 1.66, 1.68, 1.67, 1.64, 1.62, 1.53, 1.39, 1.25, 1.09, 0.93, 
                                                                                                        0.71, 0.51, 0.3, 0.11, -0.06, -0.23, -0.39, -0.53, -0.6, -0.71, 
                                                                                                        -0.81, -0.88, -0.97, -1.02, -1.07, -1.13, -1.15, -1.18, -1.2, 
                                                                                                        -1.24, -1.25, -1.32, -1.32, -1.33, -1.37, -1.38, -1.41, -1.43, 
                                                                                                        -1.42, -1.47, -1.45, -1.46, -1.44, -1.47, -1.47, -1.5, -1.49, 
                                                                                                        -1.5, -1.48), treatment3 = c(-1.28, -1.27, -1.35, -1.31, -1.37, 
                                                                                                                                     -1.25, -1.12, -0.97, -1.17, -1.04, -1.08, -1.35, -1.26, -1.33, 
                                                                                                                                     -1.16, -1.05, -0.93, -1.01, -1.06, -1.05, -0.93, -1.1, -1.12, 
                                                                                                                                     -0.93, -0.97, -0.85, -0.85, -0.76, -0.72, -0.82, -0.82, -0.58, 
                                                                                                                                     -0.61, -0.55, -0.49, -0.36, -0.3, -0.16, -0.23, -0.12, -0.02, 
                                                                                                                                     0.14, 0.22, 0.54, 0.75, 0.87, 1.35, 1.32, 1.51, 1.6, 1.7, 1.6, 
                                                                                                                                     1.59, 1.53, 1.2, 1.05, 0.78, 0.67, 0.56, 0.35, 0.13, -0.09, -0.11, 
                                                                                                                                     -0.35, -0.47, -0.5, -0.66, -0.7, -0.89, -0.88, -1.17, -1.01, 
                                                                                                                                     -1.03, -1.18, -0.98, -1.06, -1.07, -1.17, -1.18, -1.16, -1.31, 
                                                                                                                                     -1.21, -1.18, -1.3, -1.33, -1.14, -1.24, -1.21, -1.08, -1.27, 
                                                                                                                                     -1.23, -1.26, -1.26, -1.35, -1.38, -1.32, -1.32), position = c(195, 
                                                                                                                                                                                                    245, 295, 345, 395, 445, 495, 545, 595, 645, 695, 745, 795, 845, 
                                                                                                                                                                                                    895, 945, 995, 1045, 1095, 1145, 1195, 1245, 1295, 1345, 1395, 
                                                                                                                                                                                                    1445, 1495, 1545, 1595, 1645, 1695, 1745, 1795, 1845, 1895, 1945, 
                                                                                                                                                                                                    1995, 2045, 2095, 2145, 2195, 2245, 2295, 2345, 2395, 2445, 2495, 
                                                                                                                                                                                                    2545, 2595, 2645, 2695, 2745, 2795, 2845, 2895, 2945, 2995, 3045, 
                                                                                                                                                                                                    3095, 3145, 3195, 3245, 3295, 3345, 3395, 3445, 3495, 3545, 3595, 
                                                                                                                                                                                                    3645, 3695, 3745, 3795, 3845, 3895, 3945, 3995, 4045, 4095, 4145, 
                                                                                                                                                                                                    4195, 4245, 4295, 4345, 4395, 4445, 4495, 4545, 4595, 4645, 4695, 
                                                                                                                                                                                                    4745, 4795, 4845, 4895, 4945, 4995)), .Names = c("treatment1", 
                                                                                                                                                                                                                                                     "treatment2", "treatment3", "position"), row.names = c("195", 
                                                                                                                                                                                                                                                                                                            "245", "295", "345", "395", "445", "495", "545", "595", "645", 
                                                                                                                                                                                                                                                                                                            "695", "745", "795", "845", "895", "945", "995", "1045", "1095", 
                                                                                                                                                                                                                                                                                                            "1145", "1195", "1245", "1295", "1345", "1395", "1445", "1495", 
                                                                                                                                                                                                                                                                                                            "1545", "1595", "1645", "1695", "1745", "1795", "1845", "1895", 
                                                                                                                                                                                                                                                                                                            "1945", "1995", "2045", "2095", "2145", "2195", "2245", "2295", 
                                                                                                                                                                                                                                                                                                            "2345", "2395", "2445", "2495", "2545", "2595", "2645", "2695", 
                                                                                                                                                                                                                                                                                                            "2745", "2795", "2845", "2895", "2945", "2995", "3045", "3095", 
                                                                                                                                                                                                                                                                                                            "3145", "3195", "3245", "3295", "3345", "3395", "3445", "3495", 
                                                                                                                                                                                                                                                                                                            "3545", "3595", "3645", "3695", "3745", "3795", "3845", "3895", 
                                                                                                                                                                                                                                                                                                            "3945", "3995", "4045", "4095", "4145", "4195", "4245", "4295", 
                                                                                                                                                                                                                                                                                                            "4345", "4395", "4445", "4495", "4545", "4595", "4645", "4695", 
                                                                                                                                                                                                                                                                                                            "4745", "4795", "4845", "4895", "4945", "4995"), class = "data.frame")
</code></pre>

<p>My aim is to plot all three treatments into one graph with the deviation and a fitted line through all datapoints, therefore I did:</p>

<pre><code>x &lt;- (ggplot(example_data) 
+ geom_line(aes(x=position , y = treatment1, col = "treatment1")) 
+ stat_smooth(data = example_data, aes(x = position , y = treatment1))
+ geom_line(aes(x= position, y = treatment2, col ="treatment2"))
+ stat_smooth(data = example_data, aes(x = position , y = treatment2))
+ geom_line(aes(x=position , y = treatment3, col = "treatment3"))
+ stat_smooth(data = example_data, aes(x = position , y = treatment3)))
</code></pre>

<p>However the lines are very spiky and the stat_smooth does not seem to represent the highest peak very well. Maybe I am using the wrong tools, is there a way to represent only one line per treatment with a deviation included which however represents the datapoints more accurate than the stat_smooth is doing?  </p>

<p>As I am just a beginner in R and especially in ggplot I wonder if I could rewrite the clumsy code shorter without always mention the <code>aes(x = ..., y= ...)</code> separately. </p>