我正在生成大量的情节xlim和ylim价值,我在每个情节的基础上计算.我想把我的传说放在情节区域之外(就在实际情节周围的方框上方),但是我无法弄清楚如何在我的情节区域周围获得框的最大y值.
有没有办法做到这一点?我可以通过手动更改legend()x和y值来移动我想要的图例,但这需要很长时间才能创建我正在创建的图形数量.
谢谢!
-JM
jor*_*ran 13
这是一个基本的例子,说明了我认为你正在寻找的代码示例之一?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)
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
5092 次 |
| 最近记录: |