gpt4 book ai didi

r - 在 par(fig) 之后,不写入边距中的文本

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

使用 par(fig) 设置图形参数后并使用原始参数重置它们,不会写入图边距中的文本。
只有在绘图区域内执行另一个低级命令后,它才会再次工作。下面是一个例子:

dev.off()
plot(1:10)
op <- par(no.readonly = TRUE)
mtext("hello", adj=1, col=2) # written as expected
par(fig=c(0.1,0.6,0.5,0.8), new=TRUE)
par(op)
mtext("hello ", adj=1, col=3) # not written
mtext("hello ", adj=1, col=3, line=-1) # works inside plot region
mtext("hello ", adj=1, col=3) # still not written
text(50,20,"") # or abline # do something inside plot region
mtext("hello ", adj=1, col=3) # now it works!

这可能与我在 after par(fig), mtext is slightly off 下发布的另一个问题有关.

除了 mtext , axis也不起作用。除了 text/abline/points , title(main="dummy")也解决了问题。

这可能是R错误吗?或者我错过了什么?

最佳答案

通过反复试验,它归结为 par(mfg=c(1, 1, 1, 1)) .

plot(1:10)
op <- par(no.readonly = TRUE)
mtext("hello", adj=1, col=2) # written as expected
par(op[names(op) == "mfg"])
mtext("bye ", adj=1, col=3) # not written
mtext("hello ", adj=1, col=3, line=-1) # works inside plot region

plot(1:10)
op <- par(no.readonly = TRUE)
mtext("hello", adj=1, col=2) # written as expected
par(op[names(op) != "mfg"])
mtext("bye ", adj=1, col=3) # written as expected
mtext("hello ", adj=1, col=3, line=-1) # works inside plot region

我不清楚为什么设置接下来要绘制的图形应该禁用边距中的打印文本(但不是在图中),并且因为 mtext是用 C 实现的,需要一些努力才能解决。

关于r - 在 par(fig) 之后,不写入边距中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42395952/

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