library(oce)
## A. fake linear data
x <- seq(0, 100, 1)
f <- 1 + 2 * x
plot(x, f, pch=1)
m <- binMean1D(x, f)
points(m$xmids, m$result, pch=3, col='red', cex=3)
## B. fake quadratic data
f <- 1 + x ^2
plot(x, f, pch=1)
m <- binMean1D(x, f)
points(m$xmids, m$result, pch=3, col='red', cex=3)
## C. natural data
data(co2)
plot(co2, col='gray')
m <- binMean1D(time(co2), co2)
lines(m$xmids, m$result, type='o')
## D. 2D
x <- runif(500)
y <- runif(500)
f <- x + y
xb <- seq(0, 1, 0.1)
yb <- seq(0, 1, 0.2)
m <- binMean2D(x, y, f, xb, yb)
plot(x, y)
grid()
contour(m$xmids, m$ymids, m$result, add=TRUE, levels=seq(0, 2, 0.5), labcex=1)
mf <- binMean2D(x, y, f, xb, yb, flatten=TRUE)
text(mf$x, mf$y, round(mf$f, 1), col=2)
Run the code above in your browser using DataLab