# How to change the direction of increasing x in a plot [duplicate]

Consider the data set

data = Table[{10^-k, 10^(-2 k)}, {k, 5}]

and the plot:

ListLogLogPlot[data]

My goal is to reverse the plot direction for the abscissa. That is instead of having x increase from left to right, have x decrease when moving from left to right.

The instructions here How to change the axes' origin and direction? are not quite what is needed.

## marked as duplicate by 2012rcampion, bbgodfrey, Michael E2 plotting StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); May 27 '15 at 2:29

• You've seen this? – J. M. is away May 27 '15 at 0:14
• Based on @Guess's comment, here's a solution for you: ListPlot[data, ScalingFunctions -> {{Minus@*Log, Exp@*Minus}, "Log"}, AxesOrigin -> {1, 1}]. – 2012rcampion May 27 '15 at 1:05

The ScalingFunctions option is officially documented for BarChart and similar functions, but it actually works with the *Plot functions as well! See Belisarius's comment here.

data = Table[{10^-k, 10^(-2 k)}, {k, 5}]

ListPlot[
data,
ScalingFunctions -> {{-Log10[#] &, 10^-# &}, "Log"},
Frame -> {True, True, False, False}
]


Here I am using a plot Frame rather than the Axes because I found that the latter have a disappointing tendency to now show up in log plots unless one specifies an AxisOrigin explicitly, which is typically a pain. Fortunately, however, a frame can be effectively used in lieu of axes, and it will always show up independent of the plot range.

Some standard scaling options for ScalingFunctions are shown in its documentation, such as "Log" for simple log plots, and "Reversed" to invert the values along one axis. What you want would be a combination of "Log" and "Reverse" for the x-axis. Unfortunately, however, no more than one of these built-in versions can be applied at a time, so we have to roll our own scaling function in your case.

For each axis, you provide a pair of functions to generate the desired scaling. If you'll allow me the hand-waving explanation, here is how I envision the process. The first function is applied to the raw data to determine the transformed value that will actually be plotted. Appropriate plot tick positions are then calculated internally, and the second function (typically the inverse of the first one) is applied to their value to generate the corresponding labels, so you get the effect mentioned in the documentation, i.e. ticks and gridlines showing unscaled values at scaled locations, just like one would expect for a log-log plot.

With that in mind, the "Log" scaling would be represented by a Log10[#]& scaling function; the "Reverse" scaling by a -#& function. Combine the two, and you'll obtain your desired reversed log scaling: -Log10[#]&. To generate ticks and grid lines, you'll need the inverse of that function, which of course is 10^-#&.

This use of ScalingFunctions has been shown before on this site (I wouldn't have been able to figure this out on my own!). I can't seem to find the relevant question right now, but I will add a link when I find it.

As soon as I posted the answer, I saw the comments from @GuessWhoItIs and @2012rcampion, respectively providing the link I couldn't find, and something very close to the solution I proposed here. Hopefully my explanation may still be useful to you.

• Elegant and simple. Supremely helpful. Thanks. Can someone explain why ScalingFunctions as used is typeset in red with the warning "An unknown option name has been used"? – dantopa May 27 '15 at 15:53
• @dantopa I'm glad the answer was helpful to you! As for the red part, it's just because ScalingFunctions is documented only for BarChart and Histogram (as far as I know), but other posts on this site have shown that it works with the *Plot functions as well, as an undocumented feature. However, since it is not listed explicitly as a valid option for those functions, the MMA front-end syntax highlighter will helpfully mark it in red to indicate that it thinks it "shouldn't be there". – MarcoB May 27 '15 at 15:59
• @dantopa, to paraphrase an old saw: "if it looks broken and it works, then it ain't broken." – J. M. is away May 27 '15 at 16:17