gpt4 book ai didi

r - 对于参数 `axis` 的非整数值,函数 `mgp[3]` 表现异常

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

?par 表示关于 mgp[1:3]:

The margin line (in mex units) for the axis title, axis labels and axis line. Note that mgp[1] affects title whereas mgp[2:3] affect axis. The default is c(3, 1, 0).

?axis 表示类似的内容。然而,刻度标签通常不是放置在 mgp[2] 行,而是放置在 mgp[2] + (mgp[3] 行%% 1) 。因此,仅当 mgp[3] 为整数时,axis 似乎才按照记录的方式运行。这是 axis 中的错误,还是其他原因?

以下示例显示整数和非整数 axis 的预期输出和实际输出 mgp[3]:

par(mar = c(5, 1, 5, 1))
plot.new()
plot.window(xlim = c(0, 1), ylim = c(0, 1))
box(lty = 3)

## 'axis' puts line and labels in right place when 'mgp[3]' is integer
mgp_bottom <- c(0, 2.5, 1) # 'mgp[1]' is arbitrary
axis(side = 1, mgp = mgp_bottom)
mtext(c("labels", "line"), side = 1, line = mgp_bottom[2:3])

## 'axis' puts line in right place when 'mgp[3]' is noninteger,
## but apparently not labels
mgp_top <- mgp_bottom - c(0, 0, 1e-3)
axis(side = 3, mgp = mgp_top)
mtext(c("labels", "line"), side = 3, line = mgp_top[2:3])
mtext("LABELS", side = 3, line = mgp_top[2] + (mgp_top[3] %% 1))

enter image description here

最佳答案

这看起来确实像一个错误。我认为它发生在这里:https://github.com/wch/r-source/blob/6e61247f042985d5cb9f09034cb9e694a69082e0/src/library/graphics/src/plot.c#L944-L948 。在此上下文中,gpptr(dd)->mgp[2]par("mgp")[3] 的值,并且是一个 double 值。这里它被转换为 int,丢失了小数部分。

我不太明白这个计算的目的是什么,所以我不确定简单地将 lineoff 更改为 double 不会在其他地方引起问题。

关于r - 对于参数 `axis` 的非整数值,函数 `mgp[3]` 表现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69240099/

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