I am plotting a scatter plot(x, y) and want it to be log-valued, so I do: plot(log(x), log(y)). I’d like to deal with cases where some value in x is 0, and thus not on the plot, while the corresponding y value is nonzero.
I’d like to display the scatter with log ticks but natural number values, meaning if in log2 then the ticks should be 2^0, 2^1, 2^2, ... that would allow me to plot 0 values on the scale as well so as to not miss these points.
Here’s an example:
> x = c(0, 1, 20, 100, 200, 500)
> y = c(1, 16, 32, 105, 300, 50)
> plot(x, y)
There are six points. If I use:
> plot(log2(x), log2(y))
There are only 5 plotted, since x[0], y[0] is omitted (the x-value is 0). Therefore, I’d like to plot the log values but have tick labels to be natural numbers that are simply marked on a log scale. Then you can easily have on the same axis, 0, 2^0 (which is 1 of course), 2^1, 2^2, etc. and so on. Then the point (x[0], y[0]) will still be plotted, while keeping the log scale.
Side note: I don’t think it’s fair to downvote a post asking something very reasonable with an example. This is clearly on topic and relevant, and will come up for virtually everyone who is plotting things on a log value and cares about boundary / edge cases.
(I know some people deal with this by adding an arbitrary small constant to all points but I’d like to avoid that as it is messy.) thanks
If I understand you want to plot x versus y in the log scale?
Here and example using
latticeandlatticeExtra