Book Image

R Graph Essentials

Book Image

R Graph Essentials

Overview of this book

Table of Contents (11 chapters)
R Graph Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using smoothers on your graph


Often it is useful to see a smooth version of your dataset that highlights trends or variations in the data that are not evident by examining the data directly. LOWESS (locally weighted scatterplot smoothing) is often used for this purpose. Here is an example of smoothing using LOWESS. We plot HEIGHT against WEIGHT_2 and add a LOWESS smoother using the lines() and lowess() commands:

plot(WEIGHT_2, HEIGHT, main="LOWESS SMOOTHING EXAMPLE", 
xlab="WEIGHT (kg) ", ylab="HEIGHT (cm)", pch=19) 

lines(lowess(WEIGHT_2, HEIGHT), lwd=2, col="red")  

Let's see the data with a smooth curve, as shown in the following graph:

The smoother suggests some curvature to the data, which in this case was already evident in the raw data. In other cases, any trends or curvature might not be so apparent from the raw data, so a smoother might be very helpful.