# continuum between linear and logarithmic

A friend and I are working on a heatmap representing some population numbers. Initially we used a linear color scale by default. Then, because the numbers covered a wide range, I tried using a log color scale (as shown here). My friend said it obscured the data too much.

So I was wondering, is there a something in between ... some sort of continuum between linear scale and log scale? Can I drag a slider (so to speak) between linear and log scale? E.g. we might try "25% log and 75% linear".

I guess I could use a linear interpolation function like

f(x) = x + (log(x) - x) * L


where L is "loggishness," ranging from 0 to 1, to interpolate between a linear and a log scale.

I guess there's nothing wrong with that, but it seems ... I don't know, a bit "unnatural." Like it doesn't fit the nature of the log function. Is there a more natural way to do this?

On second thought, I could also try geometric interpolation between x and log(x). That seems to be a little more in keeping with the nature of logarithms, but ... I'm still not sure if it's "the" natural way to do it. I'm also wondering whether it would be visually misleading at all (assuming that we tell the reader what kind of scale we're using).

Am I wrong to try to display data on a somewhat/more/less loggish scale? I couldn't find anyone else talking about it on the web, but maybe I just didn't know what terms to search for.

-
One could consider the integral $\int x^\alpha \mathrm dx$ as $\alpha$ smoothly varies from $1$ to $-1$... – J. M. Feb 8 '12 at 22:43
... in other words, essentially $x^p$ for $p$ from $0$ to $1$. $\log x$ corresponds to the (scaled and translated) limit as $p \to 0+$, i.e. $\log x = \lim_{p \to 0} \frac{x^p-1}{p}$ for $x > 0$. – Robert Israel Feb 8 '12 at 22:58
@J.M., I think I understand what you're saying, but when I plot the graphs of this function, it desn't seem to resemble a gradual ramp from linear to log. Probably I'm not doing something right... – LarsH Feb 8 '12 at 23:38
Following Robert Israel's suggestion, if you have Mathematica you can use Manipulate to slide $p$ between $0$ and $1$ and check it out: Manipulate[Plot[(x^p - 1)/p, {x, 0, 10}], {p, 0.001, 1}] (There are free tools that do this, but I don't know how off hand.) – Jonas Meyer Feb 8 '12 at 23:39
@LarsH: $x^0/0$ is not defined. But if you consider $0<p\leq 1$, then you get a continuum of curves between $x-1$ and $\ln(x)$, going to $x-1$ as $p\nearrow 1$, and going to $\ln(x)$ as $p\searrow 0$. – Jonas Meyer Feb 8 '12 at 23:46

The integral of $x^n$ for $n\ne-1$ is $x^{n+1}/(n+1)$ (plus a constant), and the integral of $x^{-1}$ is $\log x$, so in a sense $\log x$ acts like $x^0$. Let's say you want to map $x_0$ to $y_0$ and $x_1$ to $y_1$, and you want the values in between to be something in between

$$y=y_0+\frac{x-x_0}{x_1-x_0}(y_1-y_0)$$

and

$$y=y_0+\frac{\log x-\log x_0}{\log x_1-\log x_0}(y_1-y_0)\;,$$

where the $x$ values might be population numbers and the $y$ values might be colour values. Then you can consider $\log x$ as the limit of $x^n/n$ as $n\to0$ and write

$$y=y_0+\frac{x^n-x_0^n}{x_1^n-x_0^n}(y_1-y_0)$$

for arbitrary $n\in[0,1]$, where $n=0$ is understood to mean the limit as $n\to0$. Indeed, by l'Hôpital

$$\lim_{n\to0}\frac{x^n-x_0^n}{x_1^n-x_0^n}=\lim_{n\to0}\frac{\frac{\mathrm d}{\mathrm dn}\left(x^n-x_0^n\right)}{\frac{\mathrm d}{\mathrm dn}\left(x_1^n-x_0^n\right)}=\lim_{n\to0}\frac{x^n\log x-x_0^n\log x_0}{x_1^n\log x_1-x_0^n\log x_0}=\frac{\log x-\log x_0}{\log x_1-\log x_0}\;.$$

So the parameter $n$ is the slider you can slide from $0$ to $1$ to go from $\log x$ to $x$. You may have some precision issues to deal with as you get close to $n=0$, and you should make sure to handle the case $n=0$ separately using the actual $\log$ function.

Here's a plot for $y_0=0,y_1=1,x_0=1,x_1=10$ and $n=0,\frac14,\frac12,\frac34,1$.

-
The plot is very cool! I can see how it works with n. Also I will need to learn how to post links to Wolfram Alpha plots. – LarsH Feb 9 '12 at 4:04
@Lars: It works just like for other links -- make the plot in Wolfram|Alpha, copy the URL from the browser's URL field, select the text with which you want to link and click the chain icon above the editor field. – joriki Apr 3 '13 at 5:16

Here is a link to an animation made with Geogebra showing the graphs of $y=x-1$ and $y=\log(x)$, with the graph of $y=\frac{x^p-1}{p}$ as $p$ varies from $0.001$ to $1$. That way you can see how well Robert Israel's suggestion might fit your needs.

(Geogebra is free and easy to use, so you can create your own sliders to experiment with different functions "between linear and logarithmic.")

-
Very cool too. Goodness, how do I choose between the two answers? – LarsH Feb 9 '12 at 4:06