# Smooth line in graph

6 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Smooth line in graph

 Hi, I’m trying to get smooth curves connecting points in a plot using "spline" but I don’t get what I whant. Eg.: x<-1:5 y <- c(0.31, 0.45, 0.84, 0.43, 0.25) plot(x,y) lines(spline(x,y)) Creates a valley between the first and second points, then peaks at 3rd, and another valley between 4th and 5th. I’m trying to get a consistently growing curve up to the 3rth point and then a decrease like with SigmaPlot spline curves or with Excel. I tried with different spline arguments and also lowess and loess, with no success. Any ideas? Thanks. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Smooth line in graph

 how about: require(splines) x<-1:5 y <- c(0.31, 0.45, 0.84, 0.43, 0.25) yy <-predict(interpSpline(x, y)) plot(x, y) lines(yy) ---- Katharine Mullen mail: Department of Physics and Astronomy, Faculty of Sciences Vrije Universiteit Amsterdam, de Boelelaan 1081 1081 HV Amsterdam, The Netherlands room: T.1.06 tel: +31 205987870 fax: +31 205987992 e-mail: [hidden email] homepage: http://www.nat.vu.nl/~kate/On Wed, 19 Sep 2007, Nestor Fernandez wrote: > Hi, > > I’m trying to get smooth curves connecting points in a plot using > "spline" but I don’t get what I whant. > > Eg.: > x<-1:5 > y <- c(0.31, 0.45, 0.84, 0.43, 0.25) > plot(x,y) > lines(spline(x,y)) > > Creates a valley between the first and second points, then peaks at 3rd, > and another valley between 4th and 5th. I’m trying to get a consistently > growing curve up to the 3rth point and then a decrease like with > SigmaPlot spline curves or with Excel. > > I tried with different spline arguments and also lowess and loess, with > no success. Any ideas? > > Thanks. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Smooth line in graph

 In reply to this post by Nestor Fernandez Try: > lines(spline(x,y, method='n', n=250)) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [hidden email] (801) 408-8111     > -----Original Message----- > From: [hidden email] > [mailto:[hidden email]] On Behalf Of Nestor Fernandez > Sent: Wednesday, September 19, 2007 2:09 PM > To: [hidden email] > Subject: [R] Smooth line in graph > > Hi, > > I'm trying to get smooth curves connecting points in a plot > using "spline" but I don't get what I whant. > > Eg.: > x<-1:5 > y <- c(0.31, 0.45, 0.84, 0.43, 0.25) > plot(x,y) > lines(spline(x,y)) > > Creates a valley between the first and second points, then > peaks at 3rd, and another valley between 4th and 5th. I'm > trying to get a consistently growing curve up to the 3rth > point and then a decrease like with SigmaPlot spline curves > or with Excel. > > I tried with different spline arguments and also lowess and > loess, with no success. Any ideas? > > Thanks. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Smooth line in graph

 Both worked, thanks! N. Fernandez > Katharine Mullen: > > require(splines) > x<-1:5 > y <- c(0.31, 0.45, 0.84, 0.43, 0.25) > yy <-predict(interpSpline(x, y)) > plot(x, y) > lines(yy) >   > Greg Snow: > lines(spline(x,y, method='n', n=250)) ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Smooth line in graph

 In reply to this post by Gregory Snow Sorry, I answered too quickly. It worked with the "simplified" example I provided but not with non-regular intervals in x: x<-c(-45,67,131,259,347) y <- c(0.31, 0.45, 0.84, 0.43, 0.25) plot(x,y) lines(spline(x,y, method='n', n=250)) #or: lines(predict(interpSpline(x, y))) Produce the same decrease between first two points and the shape is quite different to that produced by sigmaplot -I need comparable figures. Changing "method" and "n" arguments did not help. Sorry for bothering. Any other suggestion? Greg Snow escribió: > Try: > >   >> lines(spline(x,y, method='n', n=250)) >>     > > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.