在R中的fill.contour函数中添加点 [英] Adding points to filled.contour function in R
问题描述
我试图在R中的 filled.countour
函数中添加点。但是我没有获得任何成功。
我遵循了这个旧帖子。我的图只显示了一个绿色的点。我正在寻找一个按颜色带指定的颜色变化的点序列(在本例中为 PointColors
)。无法找出原因...
I am trying to add points to filled.countour
function in R. But I am not getting any success.
I followed this old post. My plot just shows a dot in green. I am looking for a sequence of points which changes color as specified by a color band (PointColors
in this case) . Cannot figure out why...
这是我的代码:
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)})
这是情节。
Here is the plot.
推荐答案
我认为,如果您查看一下fill.contour的xy维度已缩放为[0,1]的代码,并且需要将点调用缩放到同一变换,您会发现
I think you will find if you look at the code that the x-y dimensions of filled.contour have been scaled to [0,1] and that you need to scale your points call to the same transform.
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)
)
有点奇怪的情节,但似乎正是您要的。
Kind of a strange plot, but appears to be what you are asking for.
这篇关于在R中的fill.contour函数中添加点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!