D.Mac - 7 months ago 64

R Question

I'm trying create smooth lines on a plot which include the maxima of the data points. I've searched around a lot and have tinkered with loess() and ksmooth() but I'm yet to make it work.

My best attempt so far has been with ksmooth() but the line doesn't pass through the maximum data point

I'm a chemist, not a statistician, so the methods/descriptions of various smoothing techniques often go over my head. Any suggestions would be really appreciated.

**Edit:** Just wanted to make a few things clearer. Basically what I'm after is a smoothed version of the following plot with the line passing through the maximum y value.

To generate the plot in the first picture I used the following code:

`plot(ChiM~Temp, xlim=c(2,6), ylim=c(0,0.225), lwd=2, pch=16, col='red',subset=(v=='20'), main='Out-of-Phase AC Suscetability Plot', xlab='Temperature (K)', ylab=expression(chi[M]*'" (cm'^3*~'mol'^-1*')'))`

setone <- subset(DSM32ac, v=='20') #v=20 is the subset of the data I have provided

attach(setone)

lines(ksmooth(Temp, ChiM, 'normal', bandwidth=0.5), col='red',lwd=2)

I hope this makes things a little clearer. If you need any more information to answer this question just let me know.

Answer