r - 在 R 中向 fill.contour 添加点 - 在正确的位置

标签 r plot

我想为现有 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使用两种不同的坐标系,一种用于填充轮廓,一种用于图例。要解决您的问题,您必须使用其他功能,或者将您的 pointsplot.axes争论 :

filled.contour(x,y,z, col=rev(heat.colors(n=20, alpha=0.7)), nlevels=15,
               plot.axes={points(0,0)})

enter image description here

关于r - 在 R 中向 fill.contour 添加点 - 在正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19429350/

相关文章:

r - 如何在 R 中绘制这样的图形?

matplotlib - Python 不断覆盖先前情节的 hist 但不使用所需的情节保存它

r - 旋转更长的多列,同时旋转更宽的其他列

在 R 中复制矩阵的行

R:将图例中的文本以及图中的 xlab 和 ylab 参数设为粗体?

r - 如何调整大小并以 png 格式保存绘图?

r - 绘图随机性

python - 在 TF-IDF 中结合 Unigram 和 Bigram

r - 以离散比例在每个面网格中写入文本

python - python中的数据插值