Search code examples
rplotlogarithm

Extend an axis limit to -1 when that axis is logarithmic in R


I am doing the following:

x = c(0, 1, 2, 3, 4, 5)
y = x ^ 2
plot(x, y, log="y")

What I want is that the graph also show me the scatter point at (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.


Solution

  • No, what you are asking is mathematically impossible, because log(0) = -Inf. The point (0, 0) cannot be shown on a log-scale plot.

    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.