我正在尝试为 R 图制作整洁的 xlim
和 ylim
值。我想:1) 将 xlim[2]
舍入到大于值向量中最大值的最接近的 0.5 倍数,以及 2) 舍入 xlim[1]
到小于值向量中最小值的最接近的 0.5 倍数。
例如
x <- c(1.2, 2, 3.4)
y <- c(0.7, 2, 3.7)
# The desired lim values are then
xlim <- c(1, 3.5)
ylim <- c(0.5, 4)
plot(x, y, xlim= xlim, ylim= ylim)
提前感谢您的任何提示!
最佳答案
pretty
将计算这些值,您可以使用 range
来选择终点,
range(pretty(x))
[1] 1.0 3.5
range(pretty(y))
[1] 0.5 4.0
关于将 float(x) 舍入到最近的 .5 即 > x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660456/