【发布时间】:2017-02-11 16:49:57
【问题描述】:
我在 2D 的单位圆内有几个点。点(红色、绿色)来自两个类别之一。
library(plotrix)
# draw points within circle
n <- 100
d <- data.frame(x= rnorm(n),
y= rnorm(n))
d <- d[sqrt(d$x^2 + d$y^2) < 1, ]
d$value <- ifelse(d$x > 0, 2, 3)
plot(d$x, d$y, xlim=c(-1,1), ylim=c(-1,1), pch=16, asp=1, col=d$value)
draw.circle(0,0,1)
现在我想用平滑的热图覆盖图,指示每个组的区域。
library(akima)
library(scales)
# estimate surface
nxy <- 100
xyo <- seq(-1, 1, len=nxy)
int <- interp(x = d$x, y = d$y, z = d$value,
extrap = T,
xo = xyo, yo = xyo,
nx = nxy, ny=nxy,
linear = T)
colors <- alpha(colorRampPalette(c("red", "yellow", "green"))(40) , .4)
image(xyo, xyo, int$z, add = T, col = colors)
到目前为止一切顺利。我的问题是找到一种方法将热图外推到圆的边缘,这样它就会填满整个圆。有一个论点extrap。在文档中它说:logical flag: should extrapolation be used outside of the convex hull determined by the data points?。我将它设置为TRUE,但是,这似乎不起作用。
任何想法如何估计覆盖整个圆的光滑表面?
【问题讨论】:
-
packageVersion("akima")? -
akima版本 0.6-2 -
好吧,我在细节里找到原因了:
No extrapolation can be performed for the linear case.嗯,更好的RTFM :)