Question

I have a couple of data points that I need to "connect" with a curve. The point I am trying to make is that the data points are not monotonically increasing so I want to draw a smooth line through them that obviously goes up and down.

I have had moderate success with the smooth.spline function. Is there any way to make it look more "hand drawn"? Instead of zig-zag'ing forth and back between the points?

Here's the code that I am using right now:

x <- c(.55, .65, .75, .725, .825, .925)
y <- c(.6, .75, .9, .65, .8, .95)
plot(x, y, xlim=c(.5, 1), ylim=c(.5, 1))
lines( smooth.spline(x, y, spar=.01), col='red' )
Was it helpful?

Solution

You could use xspline.

xspline(x,y, shape= -1 )

will draw the line going through the points with curvature, changing the shape argument will change the amount of curve (and even miss the middle points by a small amount if desired).

OTHER TIPS

How about ggplot2

require(ggplot2)
qplot(x,y,geom="smooth")

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top