gpt4 book ai didi

r - ggplot scale_continuous expand 参数如何工作?

转载 作者:行者123 更新时间:2023-12-03 15:10:17 25 4
gpt4 key购买 nike

我想弄清楚如何scale_continuous() expand论证有效。根据 scale_continuous documentation :

A numeric vector of length two giving multiplicative and additive expansion constants. These constants ensure that the data is placed some distance away from the axes. The defaults are c(0.05, 0) for continuous variables, and c(0, 0.6) for discrete variables.



由于它们是“扩展常数”,因此它们不是实际单位。有没有办法将它们转换为一些实际测量值来预测实际输出?对于除 0 以外的任何内容,我只是尝试随机数,直到它起作用为止。必须有更合适的方法来解决这个问题。

最佳答案

该文件非常清楚。如果您设置 limits手动,会更清楚。我将举一些例子来说明它是如何工作的:
第一个参数给出等于其乘以极限范围的扩展;

ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(limits = c(1, 7), expand = c(0.5, 0))
# right most position will be 7 + (7-1) * 0.5 = 10
第二个给出了添加到轴两端的绝对扩展:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(limits = c(1, 7), expand = c(0.5, 2))
# right most position will be 7 + (7-1) * 0.5 + 2 = 12
最后,同样的扩展适用于轴的两端。

2019-01-23:我从@C.Liu 那里了解到新的 expand_scale函数可以用来实现 不同 下限和上限的扩展。 multiadd参数类似于 expand = 所需的两个值但允许长度为 2 的向量用于设置下限和上限。详见 C.liu 的回答。
2020-11-25: expand_scale()至少自 3.3.2 版起已弃用,请使用 expansion()反而。这只是更名。 expansion参数名称及含义保持不变 expand_scale .

关于r - ggplot scale_continuous expand 参数如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44170871/

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