The function FUN
is applied to f
in bins specified by
xbreaks
and ybreaks
. (If FUN
is mean
,
consider using binMean2D
instead, since it should be faster.)
binApply2D(x, y, f, xbreaks, ybreaks, FUN, ...)
a vector of numerical values.
a vector of numerical values.
a vector of data to which the elements of FUN
may be
supplied
values of x at the boundaries between bins; calculated using
pretty
if not supplied.
values of y at the boundaries between bins; calculated using
pretty
if not supplied.
function to apply to the data
arguments to pass to the function FUN
A list with the following elements: the breaks in x and y
(xbreaks
and ybreaks
), the break mid-points (xmids
and
ymids
), and a matrix containing the result of applying function
FUN
to f
subsetted by these breaks.
Other bin-related functions: binApply1D
,
binAverage
, binCount1D
,
binCount2D
, binMean1D
,
binMean2D
# NOT RUN {
library(oce)
# }
# NOT RUN {
## secchi depths in lat and lon bins
if (require(ocedata)) {
data(secchi, package="ocedata")
col <- rev(oce.colorsJet(100))[rescale(secchi$depth,
xlow=0, xhigh=20,
rlow=1, rhigh=100)]
zlim <- c(0, 20)
breaksPalette <- seq(min(zlim), max(zlim), 1)
colPalette <- rev(oce.colorsJet(length(breaksPalette)-1))
drawPalette(zlim, "Secchi Depth", breaksPalette, colPalette)
data(coastlineWorld)
mapPlot(coastlineWorld, longitudelim=c(-5, 20), latitudelim=c(50, 66),
grid=5, fill='gray', projection="+proj=lcc +lat_1=50 +lat_2=65")
bc <- binApply2D(secchi$longitude, secchi$latitude,
pretty(secchi$longitude, 80),
pretty(secchi$latitude, 40),
f=secchi$depth, FUN=mean)
mapImage(bc$xmids, bc$ymids, bc$result, zlim=zlim, col=colPalette)
mapPolygon(coastlineWorld, col='gray')
}
# }
Run the code above in your browser using DataLab