gpt4 book ai didi

r - 在 R 中的 fill.contour 图中绘制一个框?

转载 作者:行者123 更新时间:2023-12-04 09:46:01 24 4
gpt4 key购买 nike

我试图在 fill.contour 图中绘制一个框,但不幸的是,当我在创建了 Filled.contour 图之后绘制 lines() 时,由于比例尺迫使图像向左移动,因此图形向右移动,但框保持在相同的坐标。这是我的代码的样子:

dev.new(width=6,height=7)
mypredict<-matrix(data=mypredict,nrow=20,ncol=25)
filled.contour(x=seq(from=-1.5,to=1.5,length=20),
y=seq(from=1,to=3.75,length=25),
z=mypredict,
col=hsv(h=seq(from=2/3,to=0,length=20),s=1,v=1)
)
top <- 3.42
bot <- 1.56
lines(c(-1,-1),c(bot,top))
lines(c(1,1),c(bot,top))
lines(c(-1,1),c(top,top))
lines(c(-1,1),c(bot,bot))

有谁知道我如何在 fill.contour 函数中绘制这些线?否则,线条不会正确绘制到主图像上,因为图表的比例/图例位于右侧。

谢谢!

最佳答案

filled.contour 的手册页解释问题(并给出解决方案)

This function currently uses the ‘layout’ function and so is restricted to a full page display. As an alternative consider the ‘levelplot’ and ‘contourplot’ functions from the ‘lattice’ package which work in multipanel displays.

The output produced by ‘filled.contour’ is actually a combination of two plots; one is the filled contour and one is the legend. Two separate coordinate systems are set up for these two plots, but they are only used internally - once the function has returned these coordinate systems are lost. If you want to annotate the main contour plot, for example to add points, you can specify graphics commands in the ‘plot.axes’ argument. An example is given below.



所以基本上你传递一些指令作为 plot.axes参数覆盖标准行为。

在你的例子中:
filled.contour(x = seq(from=-1.5,to=1.5,length=20),
y = seq(from=1,to=3.75,length=25), z = mypredict,
col = hsv(h=seq(from=2/3,to=0,length=20),s=1,v=1),
plot.axes = {axis(1); axis(2); rect(left, bottom, right, top);})

请注意,您必须重新创建两个轴,否则它们将不会被绘制。此外,无需使用 lines声明,当有 rect 时功能! :)

希望这可以帮助

关于r - 在 R 中的 fill.contour 图中绘制一个框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3529212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com