gpt4 book ai didi

R 图形 : axis label placement relative to tick labels?

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

我想制作一个简单的 R 图,y 轴标签位于 y 轴刻度标签上方。我用下面的代码创建了我喜欢的东西。但是它需要对 at 进行一些摸索。图形参数。

问:有没有更简单的方法来做到这一点?有没有办法查询 y 轴刻度标签的宽度,以便我可以使用该信息将 y 轴标签居中放置在它们上方?

set.seed(1)
n.obs <- 390
vol.min <- .20/sqrt(252 * 390)
eps <- rnorm(n = n.obs, sd = vol.min)
windows(width = 5.05, height = 3.8)
plot(eps, main = "Hello World!", las=1, ylab="")
mtext(text="eps", side=3, at=-60)

my plot

最佳答案

您可以使用 `par("usr") 获取用户坐标的范围,然后转换边距的单位。通过使绘图区域非标准,您增加了额外的麻烦。在标准的 7 x 7 设备上,这有效:

mtext(text="eps", side=3, at=usrcoord.x.left-0.075*diff(range(par("usr")[1:2]) ))

但是在较小的绘图窗口上,您需要使用:
mtext(text="eps", side=3, at=usrcoord.x.left-0.1*diff(range(par("usr")[1:2]) ))

关于R 图形 : axis label placement relative to tick labels?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8101403/

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