当轴在 R 中是对数时,将轴限制扩展到 -1 [英] Extend an axis limit to -1 when that axis is logarithmic in R
问题描述
我正在做以下事情:
x = c(0, 1, 2, 3, 4, 5)
y = x ^ 2
plot(x, y, log="y")
我想要的是图表还向我显示 (x, y)=(0, 0) 处的散点.
What I want is that the graph also show me the scatter point at (x, y)=(0, 0).
我知道log(0) = -Inf
.当我在做 log(x)
时就是这种情况,但在这里我没有做 log(x)
.相反,我只是将 y 轴的比例更改为对数.因此,我需要知道是否有某种方法可以让我同时显示散点 (x, y) = (0, 0).
I know that log(0) = -Inf
. This will be the case when I am doing log(x)
but here I am not doing log(x)
. Rather, I am just changing the scale of y-axis to be logarithmic. Therefore, I need to know if there is some way for me to display the scatter point (x, y) = (0, 0) as well.
推荐答案
不,您要问的在数学上是不可能的,因为 log(0) = -Inf
.点 (0, 0) 无法显示在对数刻度图上.
No, what you are asking is mathematically impossible, because log(0) = -Inf
. The point (0, 0) cannot be shown on a log-scale plot.
对数刻度是通过对数据值进行对数转换并对轴刻度处的值取幂来生成的.例如,要以 log-10 的比例绘制值 100,首先将 100 对数转换为 log10(100) = 2
,然后将相应的轴刻度从 2 转换为 10^2 = 100
.因此,要在对数刻度图中绘制值 0,您仍然需要计算 log10(0)
,即使相应的轴刻度为 10^-Inf = 0
代码>.
A log-scale is produced by log-transforming the data values and exponentiating the values at the axis ticks. For example, to plot the value 100 in a log-10 scale, you first log-transform 100 to log10(100) = 2
, and then you transform the corresponding axis tick from 2 to 10^2 = 100
. Thus, to plot the value 0 in a log-scale plot, you still need to calculate log10(0)
, even if the corresponding axis tick would be 10^-Inf = 0
.
这篇关于当轴在 R 中是对数时,将轴限制扩展到 -1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!