在R中为fill.contour函数添加点

时间:2013-06-10 01:58:56

标签: r plot contour

我正在尝试在R中为filled.countour函数添加点数。但我没有取得任何成功。 我跟着这个old post。我的情节只显示一个绿色圆点。我正在寻找一系列点,这些点会改变颜色带所指定的颜色(在这种情况下为PointColors)。无法弄清楚为什么......

这是我的代码:

dat1 <-structure(c(5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 8.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 6.9, 5.5, 8.5, 5.5, 6.9, 6.9, 5.5, 5.5, 5.6, 6.9, 5.5, 5.5, 5.5, 8.1, 5.5, 5.5, 5.5, 5.5, 5.5, 7.5, 5.5, 5.5, 5.5, 7.5, 5.7, 4.6, 5.7, 5.5, 5.5, 5.7, 6.5, 3.2, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 8.2, 5.5, 8.2, 5.5, 5.5, 5.6, 5.5, 5.5, 5.1, 5.5, 5.5, 5.5, 5.5, 6.3, 5.5, 3.6, 5.5, 5.5, 5.5, 5.5, 5.5, 6.2, 5.4, 6.6, 5.5, 5.8, 6.2, 5.5, 5.5, 5.5, 5.6, 5.4, 5.5, 5.8, 5.5, 5.5, 5.5, 6.1, 5.5, 6.5, 2.3, 5.5, 6.1, 5.5, 5.5, 7, 5.5, 5.8, 5.5, 5.5, 7.6, 4.1, 5.5, 6.8, 4.6, 1.5, 5.5, 5.5, 5.7, 5.7, 5.5, 3.4, 5.7, 5.5, 5.5, 5.5, 5.5, 5.7, 7.4, 5.7, 5.5, 5.7, 5.5, 5.5, 5, 1, 5.5, 4.2, 2.2, 5.5, 4.7, 3.2, 5.5, 4.5, 4.5, 4, 2.4, 5.5, 2.5, 4.1, 5.7, 5.5, 1.9, 3.6, 4.6, 3, 4.6, 5.5, 4, 3.7, 5.5, 4.6, 5.5, 5.5, 4.6, 4.7, 3.6, 5.5, 5.5, 4.6, 3.7, 4.6, 4.6, 6, 4, 5.5, 4.9, 1.6, 5.5, 6.6, 5.2, 6.4, 6.4, 4.9, 6.2, 6.2, 6.5, 6.4, 5.3, 5.5, 3.6, 5.7, 7.4, 5.9, 2.4, 5.3, 8.5, 5.3, 5.5, 7.4, 6, 5.5, 5.5, 3.3, 4.6, 8.5, 6.1, 5.5, 5.5, 5.5, 5.5, 6.9, 5.5, 6.5, 7, 6.4, 5.3, 8.2, 7.3, 2.4, 7.1, 6.3, 7.7, 3.9, 8.2, 6.3, 6.7, 8, 7.2, 5.6, 4.7, 7.7, 6.6, 5.2, 5.5, 5.2, 5.3, 5.2, 5.4, 5.5, 2.8, 7, 5.7, 6.8, 4.6, 6.2, 5.5, 5.8, 7.3, 5.1, 4.8, 3.5, 5.5, 5.8, 6.4, 6.7, 5.5, 5.5, 5.5, 5.5, 4.8, 6.7, 4.7, 7.2, 5.5, 3.5, 5.5, 4.9, 5.5, 5.5, 6.7, 3.7, 5.5, 5.5), .Dim = c(20L, 16L), .Dimnames = list(NULL, c("estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated", "estimated")))

Contourcolors <- colorRampPalette(c('yellow',"red"))(20)
PointColors <- c(rep('green',5),rep('blue',5))
filled.contour(dat1,col=Contourcolors,plot.axes={points((1:20),rep(.5,20),col=PointColors,cex=5,pch=19)})

这是情节。 enter image description here

1 个答案:

答案 0 :(得分:3)

我想你会发现,如果你看一下代码,那就是fill.contour的x-y尺寸已被缩放到[0,1],并且你需要将你的点调用缩放到相同的变换。

filled.contour(z=dat1,col=Contourcolors,
      plot.axes=points( x=seq(0, 1, length.out = nrow(dat1)),
                        y=rep(.5,20), 
                        col=PointColors,cex=5,pch=19)
               )

有点奇怪的情节,但似乎是你要求的。

enter image description here