ECII
ECII

Reputation: 10629

How to draw a smooth curve passing through some points

I have

plot(rnorm(120), rnorm(120), col="darkblue", pch=16, xlim=c(-3,3), ylim=c(-4,4))
points(rnorm(120,-1,1), rnorm(120,2,1), col="darkred", pch=16)
points(c(-1,-1.5,-3), c(4,2,0), pch=3, cex=3)

I want to delineate a part of a graph, by drawing a smooth curve passing through a set of points.I can define 3-4 set of points but i cannot define a function. I would like to do this in R (as opposed to GIMP) as I would like to submit as SVG. What I would like to achieve is the following

enter image description here

Is this possible? I know this is not a sophisticated graphing question but any base R solution will do.

Upvotes: 12

Views: 3073

Answers (1)

Andrey Dyachenko
Andrey Dyachenko

Reputation: 571

if I understood the question right, drawing a spline through control points should do the job:

xspline(c(-1,-1.5,-3), c(4,2,0), shape = -1)

Should look like that:

Upvotes: 20

Related Questions