The R Project SVN R

Rev

Rev 59039 | Rev 65999 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 59039 Rev 61153
Line 83... Line 83...
83
## based on examples in ?grid.xspline
83
## based on examples in ?grid.xspline
84
 
84
 
85
xsplineTest <- function(s, open = TRUE,
85
xsplineTest <- function(s, open = TRUE,
86
                        x = c(1,1,3,3)/4,
86
                        x = c(1,1,3,3)/4,
87
                        y = c(1,3,3,1)/4, ...) {
87
                        y = c(1,3,3,1)/4, ...) {
88
    plot(c(0,1), c(0,1), type="n", axes=FALSE, xlab="", ylab="")
88
    plot(c(0,1), c(0,1), type = "n", axes = FALSE, xlab = "", ylab = "")
89
    points(x, y, pch=19)
89
    points(x, y, pch = 19)
90
    xspline(x, y, s, open, ...)
90
    xspline(x, y, s, open, ...)
91
    text(x+0.05*c(-1,-1,1,1), y+0.05*c(-1,1,1,-1), s)
91
    text(x+0.05*c(-1,-1,1,1), y+0.05*c(-1,1,1,-1), s)
92
}
92
}
93
op <- par(mfrow=c(3,3), mar=rep(0,4), oma=c(0,0,2,0))
93
op <- par(mfrow = c(3,3), mar = rep(0,4), oma = c(0,0,2,0))
94
xsplineTest(c(0, -1, -1, 0))
94
xsplineTest(c(0, -1, -1, 0))
95
xsplineTest(c(0, -1,  0, 0))
95
xsplineTest(c(0, -1,  0, 0))
96
xsplineTest(c(0, -1,  1, 0))
96
xsplineTest(c(0, -1,  1, 0))
97
xsplineTest(c(0,  0, -1, 0))
97
xsplineTest(c(0,  0, -1, 0))
98
xsplineTest(c(0,  0,  0, 0))
98
xsplineTest(c(0,  0,  0, 0))
99
xsplineTest(c(0,  0,  1, 0))
99
xsplineTest(c(0,  0,  1, 0))
100
xsplineTest(c(0,  1, -1, 0))
100
xsplineTest(c(0,  1, -1, 0))
101
xsplineTest(c(0,  1,  0, 0))
101
xsplineTest(c(0,  1,  0, 0))
102
xsplineTest(c(0,  1,  1, 0))
102
xsplineTest(c(0,  1,  1, 0))
103
title("Open X-splines", outer=TRUE)
103
title("Open X-splines", outer = TRUE)
104
 
104
 
105
par(mfrow=c(3,3), mar=rep(0,4), oma=c(0,0,2,0))
105
par(mfrow = c(3,3), mar = rep(0,4), oma = c(0,0,2,0))
106
xsplineTest(c(0, -1, -1, 0), FALSE, col="grey80")
106
xsplineTest(c(0, -1, -1, 0), FALSE, col = "grey80")
107
xsplineTest(c(0, -1,  0, 0), FALSE, col="grey80")
107
xsplineTest(c(0, -1,  0, 0), FALSE, col = "grey80")
108
xsplineTest(c(0, -1,  1, 0), FALSE, col="grey80")
108
xsplineTest(c(0, -1,  1, 0), FALSE, col = "grey80")
109
xsplineTest(c(0,  0, -1, 0), FALSE, col="grey80")
109
xsplineTest(c(0,  0, -1, 0), FALSE, col = "grey80")
110
xsplineTest(c(0,  0,  0, 0), FALSE, col="grey80")
110
xsplineTest(c(0,  0,  0, 0), FALSE, col = "grey80")
111
xsplineTest(c(0,  0,  1, 0), FALSE, col="grey80")
111
xsplineTest(c(0,  0,  1, 0), FALSE, col = "grey80")
112
xsplineTest(c(0,  1, -1, 0), FALSE, col="grey80")
112
xsplineTest(c(0,  1, -1, 0), FALSE, col = "grey80")
113
xsplineTest(c(0,  1,  0, 0), FALSE, col="grey80")
113
xsplineTest(c(0,  1,  0, 0), FALSE, col = "grey80")
114
xsplineTest(c(0,  1,  1, 0), FALSE, col="grey80")
114
xsplineTest(c(0,  1,  1, 0), FALSE, col = "grey80")
115
title("Closed X-splines", outer=TRUE)
115
title("Closed X-splines", outer = TRUE)
116
 
116
 
117
par(op)
117
par(op)
118
 
118
 
119
x <- sort(stats::rnorm(5))
119
x <- sort(stats::rnorm(5))
120
y <- sort(stats::rnorm(5))
120
y <- sort(stats::rnorm(5))
121
plot(x, y, pch=19)
121
plot(x, y, pch = 19)
122
res <- xspline(x, y, 1, draw=FALSE)
122
res <- xspline(x, y, 1, draw = FALSE)
123
lines(res)
123
lines(res)
124
## the end points may be very close together,
124
## the end points may be very close together,
125
## so use last few for direction
125
## so use last few for direction
126
nr <- length(res$x)
126
nr <- length(res$x)
127
arrows(res$x[1], res$y[1], res$x[4], res$y[4], code=1, length=0.1)
127
arrows(res$x[1], res$y[1], res$x[4], res$y[4], code = 1, length = 0.1)
128
arrows(res$x[nr-3], res$y[nr-3], res$x[nr], res$y[nr],
128
arrows(res$x[nr-3], res$y[nr-3], res$x[nr], res$y[nr], code = 2, length = 0.1)
129
       code = 2, length = 0.1)
-
 
130
}
129
}
131
\keyword{aplot}
130
\keyword{aplot}