我想为现有 filled.contour
添加一个点绘图,使用以下代码:
MyFunction <- function(x,y){
return(dnorm(sqrt(x^2+y^2)))
}
wrapper <- function(x, y, my.fun, ...) {sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i], ...))}
meshstep <- 0.5
x<- seq(-20,20,meshstep)
y <-seq(-20,20,meshstep)
z <- outer(x,y,FUN = wrapper, my.fun=MyFunction)
filled.contour(x,y,z, col=rev(heat.colors(n=20, alpha=0.7)), nlevels=15)
points(0,0)
我很惊讶
points(0,0)
没有在图的原点放置一个点,而是大致位于 x=10,y=0 处。另外,locator()
似乎也在提示关于那个"new"坐标系的坐标。这是为什么?
最佳答案
你可以在这里找到详细的答案:
Plotting a box within filled.contour plots in R?
总之,filled.contour
使用两种不同的坐标系,一种用于填充轮廓,一种用于图例。要解决您的问题,您必须使用其他功能,或者将您的 points
进plot.axes
争论 :
filled.contour(x,y,z, col=rev(heat.colors(n=20, alpha=0.7)), nlevels=15,
plot.axes={points(0,0)})
关于r - 在 R 中向 fill.contour 添加点 - 在正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19429350/