gpt4 book ai didi

r - 获取 plot() 边界框值

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

我正在使用 xlim 生成大量图和 ylim我在每个地块的基础上计算的值。我想将我的图例放在绘图区域之外(就在实际绘图周围的框上方),但我无法弄清楚如何获得绘图区域周围框的最大 y 值。

有没有办法做到这一点?我可以通过手动更改 legend() 将图例移动到我想要的位置x 和 y 值,但是对于我创建的图形数量,这需要很长时间。

谢谢!

-JM

最佳答案

这是一个基本示例,说明了我认为您正在寻找使用来自 ?legend 的代码示例之一的内容。 .

#Construct some data and start the plot
x <- 0:64/64
y <- sin(3*pi*x)
plot(x, y, type="l", col="blue")
points(x, y, pch=21, bg="white")

#Grab the plotting region dimensions
rng <- par("usr")

#Call your legend with plot = FALSE to get its dimensions
lg <- legend(rng[1],rng[2], "sin(c x)", pch=21,
pt.bg="white", lty=1, col = "blue",plot = FALSE)

#Once you have the dimensions in lg, use them to adjust
# the legend position
#Note the use of xpd = NA to allow plotting outside plotting region
legend(rng[1],rng[4] + lg$rect$h, "sin(c x)", pch=21,
pt.bg="white", lty=1, col = "blue",plot = TRUE, xpd = NA)

enter image description here

关于r - 获取 plot() 边界框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7322301/

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