Figure 12-10: Rectangular area strip
12.2.4 Smoothing Points: The lowess() and loess() Functions...............
Just plotting a cloud of points, connected or not, may give you nothing but
an uninformative mess. In many cases, it is better to smooth out the data by
fitting a nonparametric regression estimator such aslowess().
Let’s do that for our test score data. We’ll plot the scores of exam 2
against those of exam 1:
> plot(testscores)
> lines(lowess(testscores))
The result is shown in Figure 12-11.
A newer alternative tolowess()isloess(). The two functions are simi-
lar but have different defaults and other options. You need some advanced
knowledge of statistics to appreciate the differences. Use whichever you find
gives better smoothing.
12.2.5 Graphing Explicit Functions......................................
Say you want to plot the functiong(t)=(t^2 +1)^0.^5 fortbetween 0 and 5.
You could use the following R code:
g <- function(t) { return (t^2+1)^0.5 } # define g()
x <- seq(0,5,length=10000) # x = [0.0004, 0.0008, 0.0012,..., 5]
y <- g(x) # y = [g(0.0004), g(0.0008), g(0.0012), ..., g(5)]
plot(x,y,type="l")
276 Chapter 12