Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Scatter Plot with Same Smooth Fitted Curve

20180603

## `geom_smooth()` using formula 'y ~ x'

\includegraphics[width=\textwidth]{figures/onepager/ggplot2:iris_scatter_smooth-1}

set.seed(26439)
ds %>%
  sample_n(100) %>%
  ggplot(aes(x=min_temp, y=max_temp)) +
  geom_point() +
  stat_smooth(method="loess")

The rather jagged line from point to point does not give a very convincing picture of any relationship between the two variables. A common approach is to introduce a statistical function to “fit” a single smoother line to the points. We aim to draw a smoother line from left to right the follows the points but without the requirement of going through every point.

The resulting plot here uses ggplot2::geom_smooth() with a so called locally weighted scatterplot smoothing method or LOESS to produce the smoothed line. As a result we can observe statistically something of a relationship between the two variables although it is not a simple relationship.


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.